syscalls
send() — Linux system interface
Send bytes on a connected socket. Successful stream sends can be short and do not establish that the receiver processed the data. Track positive progress, handle EINTR and wait for writable readiness on EAGAIN. MSG_NOSIGNAL suppresses SIGPIPE for that call on Linux but EPIPE still reports a broken stream. Message-oriented sockets have different semantics; this example sends one byte on a local stream. Compile the complete C example in a fresh private working directory using gcc -std=c17 -Wall -Wextra -Wpedantic -Werror example.c -o example; run ./example. POSIX interface; tested on Linux/glibc only. These are libc-facing signatures, not raw architecture-specific syscall ABIs.
Formal Syntax & Structure
linux syntaxlinux
#include <sys/socket.h>ssize_t send(int sockfd, const void *buf, size_t len, int flags);Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| sockfd | int | Connected socket descriptor. |
| buf | const void * | Readable byte buffer. |
| len | size_t | Requested byte count. |
| flags | int | Per-call flags, or 0. |
Return Value
ssize_t
Number of bytes transferred, or -1 with errno on failure.
Working Example
Example Snippetlinux
#define _GNU_SOURCE#define _POSIX_C_SOURCE 200809L#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/socket.h>
/* A failed check ends this short-lived demonstration. */#define CHECK(x) do { if (!(x)) { \ fprintf(stderr, "check failed at line %d: %s\n", __LINE__, #x); \ return EXIT_FAILURE; \} } while (0)
int main(void){ int f[2]; char b; CHECK(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, f) == 0); CHECK(send(f[0], "q", 1, MSG_NOSIGNAL) == 1); CHECK(recv(f[1], &b, 1, 0) == 1 && b == 'q'); CHECK(close(f[1]) == 0); CHECK(send(f[0], "x", 1, MSG_NOSIGNAL) == -1 && errno == EPIPE); CHECK(close(f[0]) == 0); puts("byte received; EPIPE without SIGPIPE"); return EXIT_SUCCESS;}