Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Terminating a connection in the AF_INET and AF_INET6 domains

&pagelevel(4)&pagelevel

In the AF_INET and AF_INET6 domains, a connection can be terminated using soc_close() or shutdown(). A socket can only be closed with soc_close(), but not with shutdown().

When terminating a connection a distinction is made between a “graceful disconnect” and an “abortive disconnect”. This is handled by the transport system or rather the TCP protocol machine. One of the two options is selected using the soc_close() and shutdown() functions.

The following explanations of terminating a connection using soc_close() and shutdown() are based on the situation illustrated in figure 2. A client/server connection is to be terminated via which data has been transferred in both directions.

Figure 2: Client/server connection with bidirectional data transfer

Terminating a connection (“graceful”) using soc_close()

The following steps are executed:

  1. Once the last data has been sent, server S initiates the termination of a connection on the socket in S using soc_close(). This disables writing for the socket in server S and the partner socket in client C is informed that the socket in S will no longer send data. This is a “graceful disconnect”. Following a “graceful disconnect”, the connection is still maintained, however data transmission from S to C is disabled.

  2. Once the signal for “graceful disconnect” has been received, the client C user program can read all the data that has not yet been fetched until the end of the data flow is indicated with EOF.

  3. Client C calls soc_close() for the socket in C. This sends a “graceful disconnect” to S and the connection is completely terminated. The socket is closed in C. The termination of the connection is reported in S and the socket is closed.

If C answers the “graceful disconnect” event by calling soc_close() before attempting to read any existing data, the connection is completely terminated immediately and data is lost.

Terminating a connection (“graceful”) using shutdown()

The following steps are carried out:

  1. Once the last data has been sent, server S initiates the termination of the connection on the socket in Server S using shutdown(... , SHUT_WR). This disables writing for the socket in server S and the partner socket in client C is informed that the socket in S can no longer send data. This is a “graceful disconnect”. Following a “graceful disconnect”, the connection is still maintained, however data transmission from S to C is disabled.

  2. Once the signal for “graceful disconnect” has been received, the client C user program can read all the data that has not yet been fetched until the end of the data flow is indicated with EOF.

  3. Client C calls shutdown(... , SHUT_WR) for the socket in C. This sends a “graceful disconnect” to S and the connection is completely terminated.

  4. The sockets in C and S are both closed with soc_close().

If C answers the “graceful disconnect” event by calling shutdown(... ,SHUT_WR) before attempting to read any existing data, the connection is completely terminated immediately and data is lost.

Terminating a connection (“abortive”) using soc_close()

The following steps are carried out:

  1. Server S marks its socket interface with the SO_LINGER option of the setsockopt() function and sets the l_linger delay interval in the linger structure to 0.

  2. When the server calls the soc_close() function, the “abortive” termination of the connection is initiated.There is no read or write access to the socket in Server S. The partner socket in client C is informed of the “abortive disconnect” and the socket in server S is closed.

  3. Once the signal for “abortive disconnect” has been received, the client C user program can no longer read data. Any existing data that has not yet been fetched from the transport system is lost.

  4. Client C can therefore only respond to the socket in server S with soc_close() and thus close the C socket.

Terminating a connection (“abortive”) using shutdown()

The following steps are executed:

  1. Server S initiates the termination of the connection using shutdown(..., SHUT_RDWR). There is no read or write access to the socket in server S now, and the partner socket in client C is informed of the “abortive disconnect”.

  2. If the client C application program has not fetched any existing data from the transport system before receiving “abortive disconnect”, this data is lost.

  3. It is therefore only meaningful to answer with shutdown(...,SHUT_RDWR) in client C and to close both sockets in server S and client C with soc_close().