Thread: Wait for data from recv()

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    26

    Wait for data from recv()

    Hello!

    Is there any way to make a program sleep until it has data from with a recv()?

    Many thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Without effort, recv() is blocking.
    So yes, your program is asleep in a recv() without data.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    deletedforumuser
    Guest
    If you are trying to "unblock" accept() and recv()...you could just use



    Code:
    u_long* arg = 1; 
    
    ioctlsocket(thesocket, FIONBIO, &arg);

    Not sure if that's what you meant.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    does blocking mean , so you block data from recv , send?

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Blocking means that a system call "blocks" until some condition is satisfied. In the case of recv(), it means "wait until some data is available", and in send() it would mean "wait until the data has been sent".

    A non-blocking call is one that returns immediately, and you have to check some other way if some data was received or sent, or whatever it may be.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. recv() returns 0 the second time
    By Overlord in forum Networking/Device Communication
    Replies: 7
    Last Post: 07-10-2009, 04:09 AM
  2. Question about recv
    By carrotcake1029 in forum Networking/Device Communication
    Replies: 2
    Last Post: 02-26-2009, 02:10 PM
  3. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  4. Signals, fork(), wait() and exec()
    By DJTurboToJo in forum C Programming
    Replies: 7
    Last Post: 03-18-2008, 09:14 AM
  5. recv()
    By afisher in forum Networking/Device Communication
    Replies: 3
    Last Post: 03-24-2004, 05:32 PM