473,785 Members | 2,618 Online
Bytes | Software Development & Data Engineering Community
+ 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 7072
"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******** *************@p hobos.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<f ile_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
3121
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
2494
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, there is not a such function of ifstream class. Is there not a such function in standard C++ ? Or is there another way to get?
9
10904
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 the wheel, right? Everything so far is working well with the Active Directory. The problem I am having is with adding File Permissions to a directory. I am currently using some code courtesy of "Willy Denoyette "
2
5047
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 folder structure and naming conventions and then send a Net send message to those users telling them to rectify. The information I want to get is when you select the file/folder and then: Properties -> Security Tab -> Advanced Button -> Owner Tab ->...
6
11181
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 calls? I need this because I don't want to create a regular file on disk (reasons for which are many , say directory permissions ), but being a file pointer, someone can use that pointer as a regular file descriptor for reading and writing. ...
3
5273
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 is about Python or POSIX. In the following, the first time through, everything works. On the second connection, though, the same file descriptor as the first connection may be re-used, but for some reason, trying to do os.read/close on that...
0
6030
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 are duplicated in each block group. Group descriptor table is an array of group desciptors Each block group has it's own group descriptor. And it is stored in group discriptor table in sequential manner. In other word each block group has all...
3
6250
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 that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" ...
3
5402
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 that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office"...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10095
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9954
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8979
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.