c - Why does the RST packet not need the TIME_WAIT state? -
i know time_wait
prevent delayed segments 1 connection being misinterpreted being part of subsequent connection. segments arrive whilst connection in time_wait wait state discarded.
in experiment, can't see time_wait
when client sends rst packet instead of fin packet. why?
server
while (1) { int len = sizeof(struct sockaddr); fd = accept(sfd, &remote, &len); read(fd, buf, sizeof(buf)); strcpy(buf, "hello client"); write(fd, buf, strlen(buf)); close(fd); }
client
res = connect(sfd, result->ai_addr, result->ai_addrlen); strcpy(buf, "hello server!"); write(sfd, buf, strlen(buf)); close(sfd);
note: client sends rst instead of fin because not read buffered data sent server before closing socket.
when close(2)
connection pending of receiving data, connection broken, not reading pending data (that can in buffer, acknowledged, unacknowledged or in transit) breaking state machine , provokes rst
(which sent host other end, on response data segment arrives side of connection). if, suggested, read rfc document, connection in error state , reply rst
frame every packet receives... not anymore in time_wait
state.
calling close(2)
before reading eof
(an unblocking read of 0 bytes, when have received fin
other end) condition is protocol error, receiving side (you) lossing remaining data in transit side. have system call shutdown(2)
purpose of signalling intention of not writing more data (half closing sending side), , allow wait remaining data come, , forces side send fin
other end , put connection in fin_wait1
state (waiting ack
of fin
and/or fin&ack
other side)
note
time_wait
state state ensure in-transit
packet has enough time arrive @ destination , correctly processed. connection has failed both ends unsynchronized, there's no sense on waiting packet arrive, cannot correctly processed. no packet sent in response rst
, connection goes closed
state.
rfc-793 says:
sec 3.4 establishing connection
[...]
reset processing in states except syn-sent, reset (rst) segments validated checking seq-fields. reset valid if sequence number in window. in syn-sent state (a rst received in response initial syn), rst acceptable if ack field acknowledges syn. receiver of rst first validates it, changes state. if receiver in listen state, ignores it. if receiver in syn-received state , had been in listen state, receiver returns listen state, otherwise receiver aborts connection , goes closed state. if receiver in other state, aborts connection , advises user , goes closed state.
so, can read... no time_wait
state rst
in case.
Comments
Post a Comment