Socket Programming.. Stream sockets (SOCK_STREAM) provide a reliable, bidirectional, byte-stream communication channel. Datagram sockets (SOCK_DGRAM) allow data to be exchanged in the form of messages called datagrams. Socket I/O can be performed using the conventional read() and write() system calls, or using a range of socket-specific system calls (e.g., send(), recv(), sendto(), and recvfrom()). By default, these system calls block if the I/O operation can’t be completed immediately. Nonblocking I/O is also possible, by using the fcntl() F_SETFL operation (Section 5.3) to enable the O_NONBLOCK open file status flag. #include <sys/socket.h> int socket(int domain, int type, int protocol); Returns file descriptor on success, or –1 on error #include <sys/socket.h> int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); Returns 0 on success, or –1 on error #include <sys/socket.h> int listen(int sockfd, int backlog); #include <sy...
8.4 Catching and Ignoring Signals—sigaction The sigaction function allows the caller to examine or specify the action associated with a specific signal. The sig parameter of sigaction specifies the signal number for the action. The act parameter is a pointer to a struct sigaction structure that specifies the action to be taken. The oact parameter is a pointer to a struct sigaction structure that receives the previous action associated with the signal. If act is NULL, the call to sigaction does not change the action associated with the signal. If oact is NULL, the call to sigaction does not return the previous action associated with the signal. SYNOPSIS #include <signal.h> int sigaction(int sig, const struct sigaction *restrict act, struct sigaction *restrict oact); POSIX:CX If successful, sigaction returns 0. If unsuccessful, sigaction returns –1 and sets errno. The following table lists the mandatory errors for sigaction. Programs sometimes use signals to hand...