首页 > 代码库 > 非阻塞模式下网络读写接口返回值的处理
非阻塞模式下网络读写接口返回值的处理
Cyassl库
https://wolfssl.com/wolfSSL/Docs-wolfssl-manual-17-8-wolfssl-api-connection-session-io.html
int CyaSSL_read(CYASSL* ssl, void* data, int sz);
Return Values:
> 0 - the number of bytes read upon success.
0 - will be returned upon failure. This may be caused by a either a clean (close notify alert) shutdown or just that the peer closed the connection. Call CyaSSL_get_error() for the specific error code.
SSL_FATAL_ERROR - will be returned upon failure when either an error occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE error was received and and the application needs to call CyaSSL_read() again. Use CyaSSL_get_error() to get a specific error code.
int CyaSSL_write(CYASSL* ssl, const void* data, int sz);
Return Values:
> 0 - the number of bytes written upon success.
0 - will be returned upon failure. Call CyaSSL_get_error() for the specific error code.
SSL_FATAL_ERROR - will be returned upon failure when either an error occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE error was received and and the application needs to call CyaSSL_write() again. Use CyaSSL_get_error() to get a specific error code.
Openssl库
SSL_read
RETURN VALUES
The following return values can occur:
>0 The read operation was successful; the return value is the number of bytes actually read from the TLS/SSL connection.
0 The read operation was not successful. The reason may either be a clean shutdown due to a "close notify" alert sent by the peer (in which case the SSL_RECEIVED_SHUTDOWN
flag in the ssl shutdown state is set (see SSL_shutdown(3), SSL_set_shutdown(3)). It is also possible, that the peer simply shut down the underlying transport and the
shutdown is incomplete. Call SSL_get_error() with the return value ret to find out, whether an error occurred or the connection was shut down cleanly
(SSL_ERROR_ZERO_RETURN).
SSLv2 (deprecated) does not support a shutdown alert protocol, so it can only be detected, whether the underlying connection was closed. It cannot be checked, whether
the closure was initiated by the peer or by something else.
<0 The read operation was not successful, because either an error occurred or action must be taken by the calling process. Call SSL_get_error() with the return value ret to
find out the reason.
WARNING
When an SSL_read() operation has to be repeated because of SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE, it must be repeated with the same arguments.
SSL_write
RETURN VALUES
The following return values can occur:
>0 The write operation was successful, the return value is the number of bytes actually written to the TLS/SSL connection.
0 The write operation was not successful. Probably the underlying connection was closed. Call SSL_get_error() with the return value ret to find out, whether an error
occurred or the connection was shut down cleanly (SSL_ERROR_ZERO_RETURN).
SSLv2 (deprecated) does not support a shutdown alert protocol, so it can only be detected, whether the underlying connection was closed. It cannot be checked, why the
closure happened.
<0 The write operation was not successful, because either an error occurred or action must be taken by the calling process. Call SSL_get_error() with the return value ret
to find out the reason.
非加密
recv
RETURN VALUE
These calls return the number of bytes received, or -1 if an error occurred. The return value will be 0 when the peer has performed an orderly shutdown.
ERRORS
These are some standard errors generated by the socket layer. Additional errors may be generated and returned from the underlying protocol modules; see their manual pages.
EAGAIN The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.
EBADF The argument s is an invalid descriptor.
ECONNREFUSED
A remote host refused to allow the network connection (typically because it is not running the requested service).
EFAULT The receive buffer pointer(s) point outside the process’s address space.
EINTR The receive was interrupted by delivery of a signal before any data were available.
EINVAL Invalid argument passed.
ENOMEM Could not allocate memory for recvmsg().
ENOTCONN
The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).
ENOTSOCK
The argument s does not refer to a socket.
send
RETURN VALUE
On success, these calls return the number of characters sent. On error, -1 is returned, and errno is set appropriately.
ERRORS
These are some standard errors generated by the socket layer. Additional errors may be generated and returned from the underlying protocol modules; see their respective man-
ual pages.
EACCES (For Unix domain sockets, which are identified by pathname) Write permission is denied on the destination socket file, or search permission is denied for one of the
directories the path prefix. (See path_resolution(2).)
EAGAIN or EWOULDBLOCK
The socket is marked non-blocking and the requested operation would block.
EBADF An invalid descriptor was specified.
ECONNRESET
Connection reset by peer.
EDESTADDRREQ
The socket is not connection-mode, and no peer address is set.
EFAULT An invalid user space address was specified for a parameter.
EINTR A signal occurred before any data was transmitted.
EINVAL Invalid argument passed.
EISCONN
The connection-mode socket was connected already but a recipient was specified. (Now either this error is returned, or the recipient specification is ignored.)
EMSGSIZE
The socket type requires that message be sent atomically, and the size of the message to be sent made this impossible.
ENOBUFS
The output queue for a network interface was full. This generally indicates that the interface has stopped sending, but may be caused by transient congestion. (Nor-
mally, this does not occur in Linux. Packets are just silently dropped when a device queue overflows.)
ENOMEM No memory available.
ENOTCONN
The socket is not connected, and no target has been given.
ENOTSOCK
The argument s is not a socket.
EOPNOTSUPP
Some bit in the flags argument is inappropriate for the socket type.
EPIPE The local end has been shut down on a connection oriented socket. In this case the process will also receive a SIGPIPE unless MSG_NOSIGNAL is set.
非阻塞模式下网络读写接口返回值的处理