sendto : Resource temporarily unavailable (errno 11)

后端 未结 2 1799
甜味超标
甜味超标 2021-01-06 01:45

I am having a problem with sendto.

I have a receiver who receives UPD packets with recvfrom and then replies to the sender using sendto.

Unfortunately, I am

相关标签:
2条回答
  • 2021-01-06 02:06

    The error you are getting:

    EAGAIN or EWOULDBLOCK: The socket is marked nonblocking and the requested operation would block. POSIX.1-2001 allows either error to be returned for this case, and does not require these constants to have the same value, so a portable application should check for both possibilities.

    You set the socket to non-blocking (O_NONBLOCK). The socket is still busy sending the previous message. You cannot send another until the first has finished sending. That's why sleeping helped.

    Don't set it to non-blocking, or try again after select says you can.

    0 讨论(0)
  • 2021-01-06 02:09

    If you have to set the socket to non-blocking, you can do it safely (and only?) using select:

    select() and pselect() allow a program to monitor multiple file descriptors, waiting until one or more of the file descriptors become "ready" for some class of I/O operation (e.g., input possible). A file descriptor is considered ready if it is possible to perform the corresponding I/O operation (e.g., read(2)) without blocking.

    0 讨论(0)
提交回复
热议问题