The socket() function shall fail if: EAFNOSUPPORT The implementation does not support the specified address family. EMFILE All file descriptors available to the process are currently open. ENFILE No more file descriptors are available for the system. EPROTONOSUPPORT The protocol is not supported by the address family, or the protocol is not supported by the implementation. EPROTOTYPE The socket type is not supported by the protocol. The socket() function may fail if: EACCES The process does not have appropriate privileges. ENOBUFS Insufficient resources were available in the system to perform the operation. ENOMEM Insufficient memory was available to fulfill the request.
(man 3 socket)
I've recently encountered the case that socket()
returned a non-negative fd, while all operations(accept()
, connect()
, etc.) on it would fail. This error was found by valgrind --track-fds=yes -v
.
Does this mean that even if socket()
returns a non-negative fd
, fd
is still possible to be invalid?