Thread: nonblocking send need help

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    17

    nonblocking send need help

    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

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by sleith View Post
    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:
    1. 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.
    2. 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.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    17
    thx for the reply
    it's been solved, i did a wrong logic >.<

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tuncated uint8_t
    By Coens in forum C Programming
    Replies: 14
    Last Post: 11-24-2008, 07:57 AM
  2. Socket Send Help
    By cloudy in forum Networking/Device Communication
    Replies: 2
    Last Post: 11-13-2007, 04:17 PM
  3. sending n no of char data uning send() function,
    By thebrighter in forum Windows Programming
    Replies: 1
    Last Post: 08-22-2007, 12:26 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. LISP (DrScheme) any one?
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-31-2004, 12:52 PM