recv on nonblocking socket

This is a discussion on recv on nonblocking socket within the Networking/Device Communication forums, part of the General Programming Boards category; Hello I have a nonblocking socket and I want to do recv(). Im being confused because I know when socket ...

  1. #1
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630

    recv on nonblocking socket

    Hello

    I have a nonblocking socket and I want to do recv(). Im being confused because I know when socket is readable it can receive some data that can be only a part of the whole data..

    How should I know there is more data waiting to come so that I would store what I just got in the buffer and wait for next part of data and then process all what I got?

    Thanks for help

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    It will be readable as long as there is some data.

  3. #3
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    Isnt there some kind of error EGAIN or something like that, that recv will return when theres no more data?

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    If you call recv and there is currently no data waiting in the input buffer then it will return -1 and the error will indicate this. Sorry I don't know about getting the extended error message on unix type systems I only know about windows.

    But remember just because there is no information waiting in the input buffer there could still be some information traveling accross the network that hasn't arrive yet. tcp sockets should be treated as a stream. there is really no way to know how much data was sent unless the other side sends a header telling the reciever how much to expect or you send a deliminater at the end of all the data.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Nonblocking socket...blocking?
    By zolom in forum Networking/Device Communication
    Replies: 2
    Last Post: 07-13-2009, 12:06 PM
  2. socket programming question, closing sockets...
    By ursula in forum Networking/Device Communication
    Replies: 2
    Last Post: 05-31-2009, 05:17 PM
  3. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM
  4. How to make a nonblocking receive socket?
    By Aidman in forum Windows Programming
    Replies: 3
    Last Post: 04-30-2003, 04:28 PM
  5. socket programming recv function
    By vicky in forum Linux Programming
    Replies: 2
    Last Post: 10-29-2001, 02:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21