The interprocess-communication facilities are layered on top of the networking facilities, as shown in Figure 11.2. Data flows from the application through the socket layer to the networking layer, and vice versa. State required by the socket level is fully encapsulated within it, whereas any protocol-related state is maintained in auxiliary data structures that are specific to the supporting protocols. Responsibility for storage associated with transmitted data is passed from the socket level to the network level. Consistent adherence to this rule assists in simplifying details of storage management. Within the socket layer, the socket data structure is the focus of all activity. The system-call interface routines manage the actions related to a system call, collecting the system-call parameters (see Section 3.2) and converting user data into the format expected by the second-level routines. Most of the socket abstraction is implemented within the second-level routines. All second-level routines have names with a so prefix, and they directly manipulate socket data structures and manage the synchronization between asynchronous activities; these routines are listed in Table 11.2.
Table 11.2. Socket-layer support routines.
Routine
Function
socreate()
create a new socket
sobind()
bind a name to a socket
solisten()
mark a socket as listening for connection requests
soclose()
close a socket
soabort()
abort connection on a socket
soaccept()
accept a pending connection on a socket
soconnect()
initiate a connection to another socket
soconnect2()
create a connection between two sockets
sodisconnect()
initiate a disconnect on a connected socket
sosend()
send data
soreceive()
receive data
soshutdown()
shut down data transmission or reception
sosetopt()
set the value of a socket option
sogetopt()
get the value of a socket option
Figure 11.2. Interprocess-communication implementation layering. The boxes on the left name the standard layers; the boxes on the right name specific examples of the layers that might be used by an individual socket.
The remainder of this chapter focuses on the implementation of the socket layer. Section 11.3 discusses how memory is managed at the socket level and below in the networking subsystem; Section 11.4 covers the socket and related data structures; Section 11.5 presents the algorithms for connection setup; Section 11.6 discusses data transfer; and Section 11.7 describes connection shutdown. Throughout this chapter, references to the supporting facilities provided by the network-communication protocols are made with little elaboration. A complete description of the interaction between the network protocols and the socket layer appears in Chapter 12, and the internals of the network protocols are presented in Chapter 13.