3.9. SEGMENT ARRIVES (Part 3) and Timeouts
fifth, check the SYN bit,
SYN-RECEIVED
ESTABLISHED STATE
If the SYN bit is set, check the segment sequence number against the receive window. The segment sequence number must be in the receive window; if not, ignore the segment. If the SYN is on and SEG.SEQ = IRS then everything is ok and no action is needed; but if they are not equal, there is an error and a reset must be sent.
If a reset must be sent it is formed as follows:
<SEQ=SEG.ACK><CTL=RST>
The connection must be aborted as if a RST had been received.
FIN-WAIT STATE-1
FIN-WAIT STATE-2
TIME-WAIT STATE
CLOSE-WAIT STATE
CLOSING STATE
This case should not occur, since a duplicate of the SYN which started the current connection incarnation will have been filtered in the SEG.SEQ processing. Other SYN's will have been rejected by this test as well (see SYN processing for ESTABLISHED state).
sixth, check the URG bit,
ESTABLISHED STATE
FIN-WAIT-1 STATE
FIN-WAIT-2 STATE
If the URG bit is set, RCV.UP <- max(RCV.UP,SEG.UP), and signal the user that the remote side has urgent data if the urgent pointer (RCV.UP) is in advance of the data consumed. If the user has already been signaled (or is still in the "urgent mode") for this continuous sequence of urgent data, do not signal the user again.
TIME-WAIT STATE
CLOSE-WAIT STATE
CLOSING
This should not occur, since a FIN has been received from the remote side. Ignore the URG.
seventh, process the segment text,
ESTABLISHED STATE
Once in the ESTABLISHED state, it is possible to deliver segment text to user RECEIVE buffers. Text from segments can be moved into buffers until either the buffer is full or the segment is empty. If the segment empties and carries an EOL flag, then the user is informed, when the buffer is returned, that an EOL has been received.
If buffer size is not one octet, then do the following end-of-letter/buffer-size adjustment processing:
if EOL = 0 then
RCV.NXT <- SEG.SEQ + SEG.LEN
if EOL = 1 then
While RCV.LBB < SEG.SEQ+SEG.LEN
Do RCV.LBB <- RCV.LBB + RCV.BS End
RCV.NXT <- RCV.LBB
When the TCP takes responsibility for delivering the data to the user it must also acknowledge the receipt of the data. Send an acknowledgment of the form:
<SEQ=SND.NXT><ACK=RCV.NXT><CTL=ACK>
This acknowledgment should be piggybacked on a segment being transmitted if possible without incurring undue delay.
FIN-WAIT-1 STATE
FIN-WAIT-2 STATE
If there are outstanding RECEIVEs, they should be satisfied, if possible, with the text of this segment; remaining text should be queued for further processing. If a RECEIVE is satisfied, the user should be notified, with "end-of-letter" (EOL) signal, if appropriate.
TIME-WAIT STATE
CLOSE-WAIT STATE
This should not occur, since a FIN has been received from the remote side. Ignore the segment text.
eighth, check the FIN bit,
Send an acknowledgment for the FIN. Signal the user "connection closing", and return any pending RECEIVEs with same message. Note that FIN implies EOL for any segment text not yet delivered to the user. If the current state is ESTABLISHED, enter the CLOSE-WAIT state. If the current state is FIN-WAIT-1, enter the CLOSING state. If the current state is FIN-WAIT-2, enter the TIME-WAIT state.
and return.
USER TIMEOUT
For any state if the user timeout expires, flush all queues, signal the user "error: connection aborted due to user timeout" in general and for any outstanding calls, delete the TCB, and return.
RETRANSMISSION TIMEOUT
For any state if the retransmission timeout expires on a segment in the retransmission queue, send the segment at the front of the retransmission queue again, reinitialize the retransmission timer, and return.