Skip to main content
GameDev.net gamedev.net
🔒 Locked

Socket streams

Started by JY Sep 10, 2003 at 9:00 AM 0 replies 750+ views
Original Post
JY
JY
I''m developing a stream implementation for sockets based on stl::streambuf but I have just come up against a timing issue which I was wondering if anyone else has had? The stream itself works fine - I can send and receive data. However, because there is a time delay between sending a request and receiving a response, I''m wondering what it the best thing to do in that time. For example, if I do: ss << request; while (!ss.eof()) { ss >> response; } .. my ss::underflow returns EOF because there is no data currently waiting on the socket. Naturally if I put a pause between the send and receive everything works fine because the response is actually at the socket. So, should my underflow return something different when the socket is open but there is no data? Or should I perform some other kind of check between the request and the response, like adding a new function bof()? (something to check if there is any data there) OR.. do I rely on a higher level wrapper to check the data coming back to see if I have received a complete response - just in case there is a pause half way through the response and there is no data again. The main problem with this is when using getline - because if I don''t return EOF when there is no data, getline will give me a blank line which could be very bad if it happens after the headers of a message have been sent.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
Fruny
Fruny
If there is no data, either block or set the ios_base::failbit flag. ios_base::eofbit would mean the socket has been (cleanly) closed by the other side.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.