Can a socket be made non-blocking only for the recv() function?

12,866

For windows, you can use ioctlsocket() to set the socket in non-blocking mode. Unfortunately these settings apply to all operations on the socket. So for your case you'll have to switch it between the receivings and the sendings.

For the records: For linux, you could have used the MSG_DONTWAIT flag in the recv() call arguments. The single call will then be non blocking.

Share:
12,866

Related videos on Youtube

alk
Author by

alk

Be thoughtful and attentive ... - but just do it! #SOreadytohelp

Updated on September 15, 2022

Comments

  • alk
    alk over 1 year

    I want to be able to call recv() without having to block, so I want to make it non-blocking, but I do not want it to be non blocking when sending data. So can a socket be made non-blocking only for the recv() function, or does the blocking/non-blocking mode affects all of the socket functions?

    • vpalmu
      vpalmu about 9 years
      Yes but last I checked recv() won't block if there's even 1 byte of data.