473,473 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Stream from file descriptor?

Given a file descriptor (from a network socket, for instance), I want to
have an iostream that reads/writes to it, so I can push and read data in
the traditional way :

sockStream << "<some stuff>" < "\r\n"

How is this possible with the standard header files?
I need this because my objects have xml'ed << operators, but now I can't
figure out how to use them on the actual network stream.

I suppose I'll have to use a temporary file then? Just thought it'd be
possible in one go..
Thanks,
--
- gipsy boy
Jul 22 '05 #1
3 7053
"gipsy boy" <x@x.pi> wrote...
Given a file descriptor (from a network socket, for instance), I want to
have an iostream that reads/writes to it, so I can push and read data in
the traditional way :

sockStream << "<some stuff>" < "\r\n"

How is this possible with the standard header files?
Nope.
I need this because my objects have xml'ed << operators, but now I can't
figure out how to use them on the actual network stream.

I suppose I'll have to use a temporary file then? Just thought it'd be
possible in one go..


You can write your own streambuf-derived class with implementation which
will redirect the output to the platform-specific functions that work
with your sockets, etc. Search the web for examples of that.

V
Jul 22 '05 #2

"gipsy boy" <x@x.pi> wrote in message
news:Ep*********************@phobos.telenet-ops.be...
Given a file descriptor (from a network socket, for instance), I want to
have an iostream that reads/writes to it, so I can push and read data in
the traditional way :

sockStream << "<some stuff>" < "\r\n"

How is this possible with the standard header files?
I need this because my objects have xml'ed << operators, but now I can't
figure out how to use them on the actual network stream.

I suppose I'll have to use a temporary file then? Just thought it'd be
possible in one go..
Thanks,


If the file descriptor is opened in blocking mode, you can use the file
descriptor resources from the Boost Iostreams Library:

http://home.comcast.net/~jturkanis/i.../?path=5.9.1.3.

Sample usage:

using namespace boost::io;
typedef stream_facade<file_descriptor_sink> fdostream;
int fd = ...;
fdostream out(fd);
out << "Hello, World!"; // writes to file descriptor fd.

This library will appear (slightly modified) in the next release of Boost
(1.33). It is available for download here

http://home.comcast.net/~jturkanis/iostreams/

Best Regards,
Jonathan
Jul 22 '05 #3
gipsy boy wrote:
How is this possible with the standard header files?
I need this because my objects have xml'ed << operators, but now I can't
figure out how to use them on the actual network stream.


It's not. There is no such thing in standard C++ as a "file descriptor".

What you can do is write a streambuffer class that does whatever system
specific read and write calls are required. There are open source
implementations out there of this, look up socket++ or something along
those lines.
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Alexandros Frantzis | last post by:
Hello! Is there a standard way to find the reason a file stream open failed (eg file doesn't exist, access rights)? Thanks.
2
by: Thorsten Knopel | last post by:
Dear all, Because of some reason, I must get a file descript from a c++ I/O stream, for example: ifstream. Under OpenUnix I have a function ifstream::fd (rdbuf->fd) to do this. But in Linux,...
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
2
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified...
6
by: Divick | last post by:
Is there a way in C++ to have a file stream which is directly mapped to memory(virtual memory) without actually having to create a file and then memory mapping that file using system dependent...
3
by: Yang | last post by:
Hi, I'm experiencing a problem when trying to close the file descriptor for a socket, creating another socket, and then closing the file descriptor for that second socket. I can't tell if my issue...
0
ashitpro
by: ashitpro | last post by:
As per the last discussion(chapter 1), here we'll try to read the group descriptor. First of all we'll try to understand what is group descriptor. AS we know, superblock and group descriptor table...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.