#include <cafe.h>
#include <cafe/network.h>

int SOLastError(void);



Return Values

Returns int value of last error (errno) encountered after a failed socket API call. The following is the list of error codes used in the current library implementation.

SO_SUCCESS No error.
SO_ENOBUFS Insufficient resources.
SO_EISCONN Socket is already connected.
SO_EOPNOTSUPP Non-supported operation.
SO_EWOULDBLOCK Requested operation would block.
SO_ECONNREFUSED Connection refused.
SO_ECONNRESET Connection reset.
SO_ENOTCONN Not connected.
SO_EALREADY For blocking sockets, indicates that there is already a previous blocked connect call on the same socket.
SO_EABORTED Indicates the operation was aborted. For example, this error can be returned for calls blocked on a socket after the socket is closed by another thread.
SO_EINVAL Invalid operation.
SO_EMSGSIZE Too large to be sent.
SO_EPIPE Specified socket has already closed.
SO_EDESTADDRREQ No destination address was specified.
SO_ESHUTDOWN Cannot send after transport endpoint shutdown.
SO_ENOPROTOOPT Non-supported option.
SO_EHAVEOOB Urgent (out-of-band) data is pending.
SO_ENOMEM Insufficient memory.
SO_EMFILE Too many sockets open. No more socket file descriptors available.
SO_EADDRNOTAVAIL The address is not available.
SO_EADDRINUSE Address is already in use.
SO_EAFNOSUPPORT Non-supported address family.
SO_EINPROGRESS Connection cannot be completed immediately.
SO_ELOWER An error in the IP layer.
SO_ENOTSOCK Specified argument is not a socket.
SO_EIEIO I/O error.
SO_ETOOMANYREFS Too many references.
SO_EFAULT Specified pointer is outside the address space.
SO_EPROTONOSUPPORT Unsupported protocol.
SO_EPROTOTYPE Unsupported socket type.
SO_ERROR Generic error.
SO_ENOLIBRM Failed to open socket resource manager.
SO_ELIBNOTREADY Socket library is not initialized.
SO_EBUSY Socket resource manager busy processing requests.
SO_EUNKNOWN Unknown error.
SO_EAPIERROR Internal API error.
SO_ERANGEINVALID Internal API error, invalid error code.
SO_ICMP_EDESTIN Destination unreachable. Either an ICMP destination unreachable packet was received, or the arp entry timed out. Call SOIcmpLastCodeType for details.
SO_ICMP_ESOURCEQ We received an ICMP source quench packet. Call SOIcmpLastCodeType for details.
SO_ICMP_ETIMEX We received an ICMP time exceeded packet. Call SOIcmpLastCodeType for details.
SO_ICMP_EPARAM We received an ICMP IP header parameter problem packet. Call SOIcmpLastCodeType for details.


Socket APIs return -1 on error, but the actual error code is stored in a thread-safe variable. This API can be used to retrieve the error code. This API is thread-safe and will return the last socket error encountered by the current thread.

In addition to SOLastError, a POSIX-style thread-safe errno variable is also supported. An alternative to using this function is to read the errno variable to get the last socket-related error code. To do this, <errno.h> must be included.

Do Not Call From

Callbacks Do not call this function from any callback function.
Interrupt handler Do not call this function from any interrupt handler.
Exception handler Do not call this function from any exception handler.

Revision History

2014/01/24 Added SO_ICMP error codes.
2013/05/08 Automated cleanup pass.
2012/08/16 Cleanup pass.
2012/01/10 Added info about SO_EMFILE error code.
2011/10/11 Updated to indicate that this API is now thread-safe and clarified text for SO_EALREADY.
2011/05/31 Improved whole descriptions.
2011/02/21 Initial version.