: Daniel> I am creating a client, and keep coming up with Operation
: Daniel> would block when I try to do a recv. How can I fix this? I
: Daniel> have tried things like: fcntl(sockfd, F_SETFL, O_NONBLOCK)
: Sounds like that one worked...
: Daniel> and
: Daniel> FD_ZERO(&readfds);
: Daniel> FD_SET(sockfd, &readfds);
: er.. the above does nothing useful, unless in conjuction with a call to
: select()
: Daniel> but theses seem not to do anything. Can anyone tell me what I
: Daniel> am doing wrong, or how I could set the socket to non
: Daniel> blocking?
: You *did* set it to nonblocking.
: Nonblocking means that every function call on the socket will return
: immediately, rather than waiting for something to happen. If the call
: can complete immediately, e.g. for recv, if there is any data available,
: then the usual success status is returned. If the call cannot complete,
: then it returns -1 with errno == EWOULDBLOCK or EAGAIN.
: If you need to wait for something to happen on a socket that is in
: nonblocking mode, use select().
: Hope this helps
: --
This works for me:
#include <netinet/tcp.h>
...
int ret = setsockopt(iDeviceId, SOL_SOCKET, TCP_NODELAY,
(char*)&sockOpt, sizeof(sockOpt));
if (ret < 0) {
perror("setsockopt");
printf("Ret = %d\n", ret);
}