views:

38

answers:

1

Hello

I want to use recv syscall with nonblocking flags MSG_NONBLOCK. But with this flag syscall can return before full request is satisfied. So,

  • can I add MSG_WAITALL flag? Will it be nonblocking?
  • or how should I rewrite blocking recv into the loop with nonblocking recv
A: 

EDIT:

Plain recv() will return whatever is in the tcp buffer at the time of the call up to the requested number of bytes. MSG_DONTWAIT just avoids blocking if there is no data at all ready to be read on the socket. MSG_WAITALL requests blocking until the entire number of bytes requested can be read. So you won't get "all or none" behavior. At best you should get EAGAIN if no data is present and block until the full message is available otherwise.

You might be able to fashion something out of MSG_PEEK or ioctl() with a FIONREAD (if your system supports it) that effectively behaves like you want but I am unaware how you can accomplish your goal just using the recv() flags.

Duck
NONBLOCK can return with only part of required message. I want to get EAGAIN form non-blocking recv, if it want to return only part of msg. So, I want nonblocking recv with "all or nothing" behaviour
osgx