The connection should be closed with the following packetdrill script `` // Establish a connection. 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 +0 bind(3, ..., ...) = 0 +0 listen(3, 1) = 0 +0 < S 0:0(0) win 32792 <mss 1000,sackOK,nop,nop,nop,wscale 7> +0 ~ +1 > S. 0:0(0) ack 1 <...> +.1 < . 1:1(0) ack 1 win 32792 +0 accept(3, ..., ...) = 4 +0 fcntl(4, F_SETFL, O_RDWR|O_NONBLOCK) = 0 +0 < . 1:3962(3961) ack 1 win 28535 +0 < F. 3962:6683(2721) ack 1 win 45489 +0.1 read(4, ..., 177) = 177 +0.1 write(4, ..., 177) = 177 +0.1 write(4, ..., 113) = 113 +0 < . 3962:7468(3506) ack 1 win 29046 +0.1 write(4, ..., 113) = -1 // current we got 113 ```
According to RFC 793, page 75, the segment text is ignored in the CLOSE-WAIT state. No state change should happen, the missing FIN bit is ignored. The following packetdrill script shows the behaviour, which is in tune with RFC 793: 0.000 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 +0.000 fcntl(3, F_GETFL) = 0x2 (flags O_RDWR) +0.000 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0 +0.000 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress) +0.000 > S 0:0(0) win 65535 <mss 1460,nop,wscale 6,sackOK,TS val 100 ecr 0> +0.050 < S. 0:0(0) ack 1 win 65535 <mss 1460,sackOK,eol,eol> +0.000 > . 1:1(0) ack 1 win 65535 +0.050 < F. 1:513(512) ack 1 win 65535 +0.000 > . 1:1(0) ack 514 win 65188 +0.000 recv(3, ..., 256, 0) = 256 +0.050 < . 1:1025(1024) ack 1 win 65535 +0.000 > . 1:1(0) ack 514 win 65444 <nop,nop,sack 1:514> +0.000 recv(3, ..., 1024, 0) = 256 +0.000 send(3, ..., 512, 0) = 512 +0.000 > P. 1:513(512) ack 514 win 65535 +0.000 < . 514:514(0) ack 513 win 65535 +0.000 close(3) = 0 +0.000 > F. 513:513(0) ack 514 win 65535 +0.000 < . 514:514(0) ack 514 win 65535