Command Details: Shutdown
Category
Extended
Details
Command Code: | 11h |
Valid for: | Instance |
Description
This command closes a TCP-connection using the FIN-flag. Note that the response does not indicate if the connection actually shut down, which means that this command cannot be used to poll non-blocking sockets, nor will it block for blocking sockets.
Command Details
Field
Contents
CmdExt[0]
(reserved, set to zero)
CmdExt[1]
Value:
Mode:
00h
Shutdown receive channel
01h
Shutdown send channel
02h
Shutdown both receive- and send channel
Response Details
(no data)
The recommended sequence to gracefully shut down a TCP connection is described below.
Application initiates shutdown:
Send shutdown with CmdExt[1] set to 01h. This will send FIN-flag to host shutting down the send channel, note that the receive channel will still be operational.
Receive data on socket until error message Object specific error (EPIPE (13)) is received, indicating that the host closed the receive channel. If host does not close the receive channel use a timeout and progress to step 3.
Delete the socket instance. If step 2 timed out, RST-flag will be sent to terminate the socket.
Host initiates shutdown:
Receive data on socket, if zero bytes received it indicates that the host closed the receive channel of the socket.
Try to send any unsent data to the host.
Send shutdown with CmdExt[1] set to 01h. This will send FIN-flag to host shutting down the send channel.
Delete the socket instance.