mitch_feaster
September 25th, 2009, 04:50 AM
So I'm getting some weird behavior with the recv function in C (berkeley sockets). It isn't blocking like it "should" be. It's behaving as though I had OR'd MSG_DONTWAIT into the flags on the call to recv, or set up the socket as non-blocking -- but I haven't done either of those two things.
Now, the reason this is "weird" to me is that it seems to be Ubuntu-specific. The same code behaves as expected in Red Hat and even Debian.
Here's how I'm calling recv:
if ( (nbytes = recv(sock, buf, MAX_MSG, 0) == -1) ) { /*recv error*/
perror("recv error");
exit(EXIT_FAILURE);
}
//we successfully returned from recv
printw("Received %d bytes of data...Such as %s\n", nbytes, buf->code);
/*In Ubuntu recv returns immediately, setting nbytes to 0!*/
And here's how I'm creating the socket:
//open socket:
if ( (sock = socket(PF_INET, SOCK_STREAM, 0)) == -1 ) {
perror("Error creating socket");
exit(EXIT_FAILURE);
}
Any ideas on why this is happening (only in Ubuntu)?
Now, the reason this is "weird" to me is that it seems to be Ubuntu-specific. The same code behaves as expected in Red Hat and even Debian.
Here's how I'm calling recv:
if ( (nbytes = recv(sock, buf, MAX_MSG, 0) == -1) ) { /*recv error*/
perror("recv error");
exit(EXIT_FAILURE);
}
//we successfully returned from recv
printw("Received %d bytes of data...Such as %s\n", nbytes, buf->code);
/*In Ubuntu recv returns immediately, setting nbytes to 0!*/
And here's how I'm creating the socket:
//open socket:
if ( (sock = socket(PF_INET, SOCK_STREAM, 0)) == -1 ) {
perror("Error creating socket");
exit(EXIT_FAILURE);
}
Any ideas on why this is happening (only in Ubuntu)?