How can I create a ip::tcp::iostream from a SOCKET descriptor?

I'm trying to convert my hand-rolled marshalling code into boost::serialization and boost::ip classes. My code gets handed a SOCKET handle (win XP). I have no control over this, the connection/server/client stuff is handled elsewhere, I just get the SOCKET after everything's already open. How can I create an iostream from that, so I can then use the Archive classes to send and receive objects over the socket? I understand the "harder" stuff (writing the overloads for my classes for input/output to a generic stream). I'm just stuck on finding that construction (or function) that will take an already opened SOCKET handle and wrap an iostream around it. any clues?

I'm just stuck on finding that construction (or function) that will take an already opened SOCKET handle and wrap an iostream around it.
It seems that ip::tcp::iostream doesn't have such a capability. But iostream is just a convenience wrapper. You can open a regular ip::tcp::socket with this overload: http://www.boost.org/doc/libs/1_41_0/doc/html/boost_asio/reference/basic_str... and then use synchronous i/o operations with asio::streambuf

Igor R wrote:
It seems that ip::tcp::iostream doesn't have such a capability. But iostream is just a convenience wrapper. You can open a regular ip::tcp::socket with this overload: http://www.boost.org/doc/libs/1_41_0/doc/html/boost_asio/reference/basic_str... and then use synchronous i/o operations with asio::streambuf _______________________________________________
Aha. Thanks. I'll look into that. Looks like the asio may be overkill for me (looking at buffers and such). My internal protocol is pretty simple, though, so I might just fall back on using serialization to dump stuff into binary string buffers and then write that out to the socket directly, avoiding asio for now.
participants (2)
-
Eric J. Holtman
-
Igor R