简体   繁体   中英

Resource temporarily unavailable, UDP socket

I'm talking to a device over a UDP socket. I send a command and then receive a response from it. The messages need to be sent every 100ms. I set a receive timeout with

struct timeval t = {.tv_sec = 0, .tv_usec = 100000};
setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, t, sizeof(t));

where fd is my socket file descriptor. Everything works fine for a long time but then I start getting a Resource temporarily unavailable error on the recvfrom(...) call. As far as I understand it happens because there is nothing in the receive buffer. I would be expecting that on the next iteration the buffer would be full, but I'm still getting Resource temporarily unavailable . In other words the system doesn't recover. Is that an issue with a socket itself, the settings on the socket, or the device?

There shouldn't be an issue with the socket or its configuration if you are getting traffic initially. You would see a different error message if that was the case.

If you're only encountering the message once or twice in a row, it could be network delay or packet loss due to some networking issue. (eg a bad switch, slow network connection, etc.)

If you consistently encountering the message (each time recvfrom is called) there may be an issue with the connection between the client and server. I would verify that the client is still sending messages and check your network connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM