What about looking at the return result of send() to see how much you actually sent?
- assuming that send() always sends the whole thing in one call is a bug.
What about the recv() end as well?
Messages can be fragmented in transit, and it's your job to reassemble them.
hole == whole
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
So just because your luck ran out, you decide that there is a problem with the universe?
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
The RFCs don't mean squat if you don't know how to write network code to begin with.
http://beej.us/guide/bgnet/
Here's an example of what you need to be doing instead of your "fire and pray" approach.
int mySend ( int socket, std::string &s ) {
const char *p = s.c_str();
size_t len = s.length();
ssize_t n;
while ( len > 0 &&
(n = send( socket, p, len, 0 )) > 0 ) {
// successfully sent some (possibly all) of the message
// if it was partially successful, advance down the string
// to the bit which didn't get sent, and try again
len -= n;
p += n;
n = 1;
}
if ( n == 0 ) {
// a send call failed to make any progress through the data
// or perhaps len itself was 0 to start with.
}
if ( n < 0 ) {
// look at errno to determine what went wrong
// some values like EAGAIN and EINTR may be worth a 2nd attempt
}
return n;
}
Elsewhere, you do
if ( mySend(socket, foo) > 0 ) {
// more stuff
}
// or
if ( mySend(socket, foo) <= 0 ) {
// panic and die
}
Now write something similar for recv(), which waits around until it has filled a buffer ending with \r\n (as defined by your RFC).
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953