什么会导致sock send()命令的“资源暂时不可用”

时间:2022-09-22 13:36:16

What can cause a Resource temporarily unavailable error on a socket send() command? The socket is setup as AF_UNIX, SOCK_STREAM. It works most of the time, but occasionally gets this error. The receiving end of the socket appears to be working properly.

什么会导致socket send()命令上的资源暂时不可用错误?套接字设置为AF_UNIX、SOCK_STREAM。它在大多数情况下都是有效的,但偶尔也会出错。插座的接收端似乎工作正常。

I know this isn't very detailed, but I'm just looking for general ideas. Thanks!

我知道这不是很详细,但我只是在寻找一般的想法。谢谢!

2 个解决方案

#1


62  

"Resource temporarily unavailable" is the error message corresponding to EAGAIN, which means that the operation would have blocked but nonblocking operation was requested. For send(), that could be due to any of:

“资源暂时不可用”是与EAGAIN对应的错误消息,这意味着操作将被阻塞,但请求了非阻塞操作。对于send(),这可能是由于:

  • explicitly marking the file descriptor as nonblocking with fcntl(); or
  • 使用fcntl()显式地将文件描述符标记为非阻塞;或
  • passing the MSG_DONTWAIT flag to send(); or
  • 通过MSG_DONTWAIT标志发送();或
  • setting a send timeout with the SO_SNDTIMEO socket option.
  • 使用SO_SNDTIMEO套接字选项设置发送超时。

#2


33  

That's because you're using a non-blocking socket and the output buffer is full.

这是因为您正在使用一个非阻塞套接字,并且输出缓冲区已满。

From the send() man page

从send()手册页

   When the message does not fit into  the  send  buffer  of  the  socket,
   send() normally blocks, unless the socket has been placed in non-block-
   ing I/O mode.  In non-blocking mode it  would  return  EAGAIN  in  this
   case.  

EAGAIN is the error code tied to "Resource temporarily unavailable"

EAGAIN是与“资源暂时不可用”绑定的错误代码

Consider using select() to get a better control of this behaviours

考虑使用select()来更好地控制这种行为

#1


62  

"Resource temporarily unavailable" is the error message corresponding to EAGAIN, which means that the operation would have blocked but nonblocking operation was requested. For send(), that could be due to any of:

“资源暂时不可用”是与EAGAIN对应的错误消息,这意味着操作将被阻塞,但请求了非阻塞操作。对于send(),这可能是由于:

  • explicitly marking the file descriptor as nonblocking with fcntl(); or
  • 使用fcntl()显式地将文件描述符标记为非阻塞;或
  • passing the MSG_DONTWAIT flag to send(); or
  • 通过MSG_DONTWAIT标志发送();或
  • setting a send timeout with the SO_SNDTIMEO socket option.
  • 使用SO_SNDTIMEO套接字选项设置发送超时。

#2


33  

That's because you're using a non-blocking socket and the output buffer is full.

这是因为您正在使用一个非阻塞套接字,并且输出缓冲区已满。

From the send() man page

从send()手册页

   When the message does not fit into  the  send  buffer  of  the  socket,
   send() normally blocks, unless the socket has been placed in non-block-
   ing I/O mode.  In non-blocking mode it  would  return  EAGAIN  in  this
   case.  

EAGAIN is the error code tied to "Resource temporarily unavailable"

EAGAIN是与“资源暂时不可用”绑定的错误代码

Consider using select() to get a better control of this behaviours

考虑使用select()来更好地控制这种行为