nonblocking send need help [Archive] - C Board

PDA

View Full Version : nonblocking send need help


sleith
03-27-2008, 08:07 PM
Hi, im in trouble with nonblocking send. When i set server to nonblocking send, the client is not received all the data, there's something missing. I have used my own buffer to make sure all the data is sent. This problem didn't happen if it's nonblocking send.

This is what happended :
Case: server send msg to client. Client is in hang mode, so doesn't call recv.
1. Server trying to send n msg and all sucess (means send return > 0)
2. when send return < 0, it should be the buffer is full.
3. Although the previous is return < 0, somehow after calling send again, it return > 0. It should be return < 0 because client doesn't call recv

What exactly happend... any help? thx :)

Cactus_Hugger
03-27-2008, 08:58 PM
Case: server send msg to client. Client is in hang mode, so doesn't call recv.
What does that mean? Your client is suicidal?
1. Server trying to send n msg and all sucess (means send return > 0)
Are you sure? send() returns >0 if something was sent - but that doesn't mean everything was sent. If the return value == the length you passed send(), then everything was sent. Otherwise, only part of it was sent.
2. when send return < 0, it should be the buffer is full.
No. send() returns <0 on error, not on buffer full. Read the man page. Now, if you're using nonblocking sockets, send() might return <0, and errno set to EAGAIN/EWOULDBLOCK.
3. Although the previous is return < 0, somehow after calling send again, it return > 0. It should be return < 0 because client doesn't call recv
Read the man page for send. Basically, for non-blocking sockets:

send() returns >0: The return value is the number of bytes sent. Check it: it might be what you passed to send, it might be less.
send() returns <0: Some error occurred. One of the possible 'errors' with nonblocking sockets is 'EWOULDBLOCK' (errno is set to this) - the socket couldn't fulfill your request, but didn't want to block, so it returned. No data was sent, and you'll need to wait for the socket to be available to send data on it.


Note: If you're using Winsock, EWOULDBLOCK is reported differently.

sleith
03-27-2008, 10:51 PM
thx for the reply
it's been solved, i did a wrong logic >.<