LISTEN(3POSIX)
π listen(3POSIX) β the POSIX Programmer's Manual, bestie edition π
okay so this is listen(3POSIX), straight out of the POSIX Programmer's Manual, and I am so ready to yap about it.
π«Ά PROLOG
Real talk first, because this part matters: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β so if you're on Linux, bestie, go consult the corresponding Linux manual page for the actual deets on Linux behavior. And lowkey? It's also possible the interface just isn't implemented on Linux at all. No cap. Check before you ship. π
β¨ NAME β¨
listen β listen for socket connections and limit the queue of incoming connections π
πΈ SYNOPSIS πΈ
#include <sys/socket.h>
int listen(int socket, int backlog);
π DESCRIPTION π
okay so here's the vibe. The listen() function shall mark a connection-mode socket β the one you pass as the socket argument β as accepting connections. It's giving "come through, I'm open for business". π
The backlog argument is a hint to the implementation, and the implementation shall use it to limit the number of outstanding connections chillin' in the socket's listen queue. Important: implementations are allowed to impose a limit on backlog and silently reduce the value you gave it. Rude? Maybe. Legal? Yes. Normally, a larger backlog value shall result in a larger or equal length of the listen queue. And implementations shall support values of backlog up to SOMAXCONN, which is defined in <sys/socket.h>. π
The implementation may include incomplete connections in its listen queue. And the limits on the number of incomplete connections queued and completed connections queued may be different. Two separate queues, two separate moods. π¦
The implementation may have an upper limit on the length of the listen queue β and that limit can be global or per accepting socket, dealer's choice. If backlog exceeds this limit, the length of the listen queue is just set to the limit. Cap it and move on. βοΈ
If listen() is called with a backlog argument value that is less than 0, the function behaves as if it had been called with a backlog argument value of 0. Negative girlies get rounded up to zero, periodt.
A backlog argument of 0 may allow the socket to accept connections, and in that case the length of the listen queue may be set to an implementation-defined minimum value. So zero isn't necessarily "nope", it's "we'll see". π
And heads up β the socket in use may require the process to have appropriate privileges to use the listen() function. So like... know your permissions. π
β RETURN VALUE β
Upon successful completions, listen() shall return 0. Otherwise, -1 shall be returned and errno is set to indicate the error. Zero is the slay, negative one is the "something's wrong". π
π₯ ERRORS π₯
The listen() function shall fail if:
EBADFβ Thesocketargument is not a valid file descriptor. Not a real one, bestie. πEDESTADDRREQβ The socket is not bound to a local address, and the protocol does not support listening on an unbound socket. No address, no listening. π«EINVALβ The socket is already connected. She's taken. πENOTSOCKβ Thesocketargument does not refer to a socket. That's just... not a socket. πEOPNOTSUPPβ The socket protocol does not supportlisten(). Wrong protocol, wrong function, sorry babe. π«Ά
The listen() function may fail if:
EACCESβ The calling process does not have appropriate privileges. Permissions check said no. πEINVALβ The socket has been shut down. She's gone, she's resting. π΄ENOBUFSβ Insufficient resources are available in the system to complete the call. The system is out of spoons. π
The following sections are informative. π’
π EXAMPLES π
None. The examples are simply not here. Iconic behavior, honestly.
π§ APPLICATION USAGE π§
None. Also empty. The page said what it said and dipped.
π RATIONALE π
None. No rationale, no explanation arc, no lore drop.
π¦ FUTURE DIRECTIONS π¦
None. The future is unspecified and honestly that's very on brand.
π SEE ALSO π
accept()connect()socket()
The Base Definitions volume of POSIX.1β2017, <sys_socket.h> β
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
okay that's the whole page, bestie, and that's a wrap on listen(3POSIX) from the POSIX Programmer's Manual β brought to you by IEEE/The Open Group, 2017 πβ¨ slay, go bind your sockets, and don't forget to check your backlog ππ
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms