SEND(3POSIX)
π SEND(3POSIX) π
okay so bestie, we're in the POSIX Programmer's Manual rn (the Linux version of this interface may be different β check the Linux man page for the deets on Linux behavior β or honestly it might not even be implemented on Linux at all, no cap π« ).
β¨ PROLOG β¨
So like, this manual page is part of the POSIX Programmer's Manual. That's the vibe. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. Lowkey important. Don't come for me if Linux does its own thing π
πΈ NAME πΈ
send β send a message on a socket. That's it. That's the whole job. Sending. Messages. On sockets. Iconic behavior honestly π
π SYNOPSIS π
#include <sys/socket.h>
ssize_t send(int socket, const void *buffer, size_t length, int flags);
Look at her. Four arguments. No notes. π
π¦ DESCRIPTION π¦
So the send() function shall initiate transmission of a message from the specified socket to its peer. Key word: initiate. It shall send a message only when the socket is connected. And if the socket is a connectionless-mode socket, the message shall be sent to the pre-specified peer address. Pre-specified!! She already knows where she's going π§
The send() function takes the following arguments:
socketβ Specifies the socket file descriptor. Your little ticket to the socket party ποΈbufferβ Points to the buffer containing the message to send. The contents!! The tea!! βlengthβ Specifies the length of the message in bytes. How much tea, exactly πflagsβ Specifies the type of message transmission. Values of this argument are formed by logically OR'ing zero or more of the following flags:MSG_EORβ Terminates a record (if supported by the protocol). End of record, periodt.MSG_OOBβ Sends out-of-band data on sockets that support out-of-band communications. The significance and semantics of out-of-band data are protocol-specific. So like, the drama is real but the meaning depends on your protocol, iykyk.MSG_NOSIGNALβ Requests not to send theSIGPIPEsignal if an attempt to send is made on a stream-oriented socket that is no longer connected. The[EPIPE]error shall still be returned. So you still get the error, you just don't get screamed at by a signal. Very demure, very mindful π
The length of the message to be sent is specified by the length argument. If the message is too long to pass through the underlying protocol, send() shall fail and no data shall be transmitted. Not even a crumb. Nothing. Zero. π
Successful completion of a call to send() does not guarantee delivery of the message. A return value of -1 indicates only locally-detected errors. Read that again bestie β success here is not a promise, it's a hope. Local errors only. The network is a mystery π
If space is not available at the sending socket to hold the message to be transmitted, and the socket file descriptor does not have O_NONBLOCK set, send() shall block until space is available. She waits. Patiently. Main character energy of patience honestly. But if space is not available at the sending socket to hold the message to be transmitted, and the socket file descriptor does have O_NONBLOCK set, send() shall fail. No waiting. No patience. Just fail. π
The select() and poll() functions can be used to determine when it is possible to send more data. Besties helping besties π«Ά
The socket in use may require the process to have appropriate privileges to use the send() function. So like, sometimes you need permission. Ask nicely. Or have privileges. Either way.
π RETURN VALUE π
Upon successful completion, send() shall return the number of bytes sent. Otherwise, -1 shall be returned and errno set to indicate the error. That's the deal. Number of bytes, or -1 plus an errno with feelings. β
π₯ ERRORS π₯
The send() function shall fail if:
EAGAINorEWOULDBLOCKβ The socket's file descriptor is markedO_NONBLOCKand the requested operation would block. She said no waiting and she meant it.EBADFβ Thesocketargument is not a valid file descriptor. That's not a socket, that's a lie π©ECONNRESETβ A connection was forcibly closed by a peer. Rude. Blocked. Unfollowed.EDESTADDRREQβ The socket is not connection-mode and no peer address is set. Where are you even going?? No destination, no message.EINTRβ A signal interruptedsend()before any data was transmitted. Nothing got through, so like, technically no harm.EMSGSIZEβ The message is too large to be sent all at once, as the socket requires. Girl. Break it up.ENOTCONNβ The socket is not connected. You can't send a message into the void.ENOTSOCKβ Thesocketargument does not refer to a socket. Again. Not a socket. π©π©ENOTSUPPLY... wait no βEOPNOTSUPPβ Thesocketargument is associated with a socket that does not support one or more of the values set inflags. Wrong flags, wrong socket, wrong era.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 typeSOCK_STREAMorSOCK_SEQPACKETand theMSG_NOSIGNALflag is not set, theSIGPIPEsignal is generated to the calling thread. Yeah. That's the scary one. That's whyMSG_NOSIGNALexists. Set it. Please. π
The send() function may fail if:
EACCESβ The calling process does not have appropriate privileges. No privileges, no send.EIOβ An I/O error occurred while reading from or writing to the file system. The disk said "not today."ENETDOWNβ The local network interface used to reach the destination is down. The network is napping π΄ENETUNREACHβ No route to the network is present. No road, no trip π£οΈENOBUFSβ Insufficient resources were available in the system to perform the operation. System said "I'm full bestie."
The following sections are informative. So like, they're the bonus content, not the main character. Still cute though.
π EXAMPLES π
None.
(Yeah. Nothing. Empty. We love a minimal queen π )
π APPLICATION USAGE π
If the socket argument refers to a connection-mode socket, the send() function is equivalent to sendto() (with any value for the dest_addr and dest_len arguments, as they are ignored in this case). Any value!! They don't even look at them. Ignored. Discarded. Not the moment.
If the socket argument refers to a socket and the flags argument is 0, the send() function is equivalent to write(). Zero flags and it's basically just write() with extra steps. Wild.
π§ RATIONALE π§
None.
(Also empty. The reasoning is vibes only apparently π)
π FUTURE DIRECTIONS π
None.
(The future is bright and also unspecified β¨)
β SEE ALSO β
connect(), getsockopt(), poll(), pselect(), recv(), recvfrom(), recvmsg(), sendmsg(), sendto(), setsockopt(), shutdown(), socket(), write()
The Base Definitions volume of POSIX.1β2017, <sys_socket.h>
Go read those too, they're the extended universe π
π 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 .
and that's the whole page, bestie!! brought to you by IEEE/The Open Group, 2017 β the original SEND(3POSIX) era. ty for reading, go send some bytes responsibly πβ¨π
π¦ 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