Blocking socket returns EAGAIN

前端 未结 4 370
孤独总比滥情好
孤独总比滥情好 2020-12-10 16:39

One of my projects on Linux uses blocking sockets. Things happen very serially so non-blocking would just make things more complicated. Anyway, I am finding that often a

相关标签:
4条回答
  • 2020-12-10 17:22

    I don't suggest this as a first-attempt fix, but if you're all out of options, you can always select() on the socket with a reasonably long timeout to force it to wait for data.

    0 讨论(0)
  • 2020-12-10 17:34

    Is it possible that you're using MSG_DONTWAIT is being specified as part of your flags? The man page says EAGAIN will occur if no data is available and this flag is specified.

    If you really want to force a block until the recv() is somewhat successful, you may wish to use the MSG_WAITALL flag.

    0 讨论(0)
  • 2020-12-10 17:42

    It's possible that you have a nonzero receive timeout set on the socket (via setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,...)) as that would also cause recv to return EAGAIN

    0 讨论(0)
  • 2020-12-10 17:43

    EAGAIN is generated by the OS almost like an "Oops! I'm sorry for disturbing you.". In case of this error, you may try reading again, This is not a serious or fatal error. I have seen these interrupts occur in Linux and LynxOS anywhere from one a day to 100 times a day.

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