udp协议下sendto与recvfrom函数对应的errno

概述

在C/C++中,使用udp socket时,sendtorecvfrom 有不同的errno

而在高阶语言Javascript中,使用udp socket, 会将两种类型的错误通过同一个事件 error 抛出来

因此,有必要将 sendtorecvfrom 对应的 errno列出来,以便在error中进行区分

var code = “a9fb4b37-0ec1-447e-b8f9-46ea94ea0880”

内容

sendto()失败时,有如下的错误码:

errnoerrmsg
[EAFNOSUPPORT]Addresses in the specified address family cannot be used with this socket.
[EAGAIN] or [EWOULDBLOCK]The socket’s file descriptor is marked O_NONBLOCK and the requested operation would block.
[EBADF]The socket argument is not a valid file descriptor.
[ECONNRESET]A connection was forcibly closed by a peer.
[EINTR]A signal interrupted sendto() before any data was transmitted.
[EMSGSIZE]The message is too large to be sent all at once, as the socket requires.
[ENOTCONN]The socket is connection-mode but is not connected.
[ENOTSOCK]The socket argument does not refer to a socket.
[EOPNOTSUPP]The socket argument is associated with a socket that does not support one or more of the values set in flags.
[EPIPE]The socket is shut down for writing, or the socket is connection-mode and is no longer connected. In the latter case, and if the socket is of type SOCK_STREAM or SOCK_SEQPACKET and the MSG_NOSIGNAL flag is not set, the SIGPIPE signal is generated to the calling thread.
[EIO]An I/O error occurred while reading from or writing to the file system.
[ELOOP]A loop exists in symbolic links encountered during resolution of the pathname in the socket address.
[ENAMETOOLONG]The length of a component of a pathname is longer than {NAME_MAX}.
[ENOENT]A component of the pathname does not name an existing file or the pathname is an empty string.
[ENOTDIR]A component of the path prefix of the pathname in the socket address names an existing file that is neither a directory nor a symbolic link to a directory, or the pathname in the socket address contains at least one non- slash character and ends with one or more trailing slash characters and the last pathname component names an existing file that is neither a directory nor a symbolic link to a directory.
[EACCES]Search permission is denied for a component of the path prefix; or write access to the named socket is denied.
[EDESTADDRREQ]The socket is not connection-mode and does not have its peer address set, and no destination address was specified.
[EHOSTUNREACH]The destination host cannot be reached (probably because the host is down or a remote router cannot reach it).
[EINVAL]The dest_len argument is not a valid length for the address family.
[EISCONN]A destination address was specified and the socket is already connected.
[ENETDOWN]The local network interface used to reach the destination is down.
[ENETUNREACH]No route to the network is present.
[ENOBUFS]Insufficient resources were available in the system to perform the operation.
[ENOMEM]Insufficient memory was available to fulfill the request.

recvfrom()失败时,有如下的错误码:

errnoerrmsg
[EAGAIN] or [EWOULDBLOCK]The socket’s file descriptor is marked O_NONBLOCK and no data is waiting to be received; or MSG_OOB is set and no out-of-band data is available and either the socket’s file descriptor is marked O_NONBLOCK or the socket does not support blocking to await out-of-band data.
[EBADF]The socket argument is not a valid file descriptor.
[ECONNRESET]A connection was forcibly closed by a peer.
[EINTR]A signal interrupted recvfrom() before any data was available.
[EINVAL]The MSG_OOB flag is set and no out-of-band data is available.
[ENOTCONN]A receive is attempted on a connection-mode socket that is not connected.
[ENOTSOCK]The socket argument does not refer to a socket.
[EOPNOTSUPP]The specified flags are not supported for this socket type.
[ETIMEDOUT]The connection timed out during connection establishment, or due to a transmission timeout on active connection.
[EIO]An I/O error occurred while reading from or writing to the file system.
[ENOBUFS]Insufficient resources were available in the system to perform the operation.
[ENOMEM]Insufficient memory was available to fulfill the request.

参考资料

posted @ 2022-10-28 11:23  西河  阅读(504)  评论(0编辑  收藏  举报