Mailing List Archive

tcp/ip shutdown problem (fwd)
Does this affect Apache?

Forwarded message:
> From dsr@w3.org Wed Sep 6 08:47:33 1995
> Message-Id: <199509061544.AA038602298@w3.org>
> To: apache-bugs@apache.org
> Subject: tcp/ip shutdown problem
> Date: Wed, 06 Sep 1995 11:44:53 -0400
> From: "Dave Raggett" <dsr@w3.org>
>
>
> You may already have dealt with this, but if not this may be of help ...
>
> Some documents cause problems for certain http servers, in that the
> last few bytes are never received by the client. On a suggestion by
> Simon Spero, I fixed this for my server with the code:
>
> /* CloseSocket lingers on close to ensure all data is sent */
>
> int CloseSocket(int skt)
> {
> char buf[10];
> struct linger linger;
>
> shutdown(skt, 1); /* send remaining data first */
>
> linger.l_onoff = 1; /* 0 is off and l_linger ignored */
> linger.l_linger = 1; /* if nonzero wait for data sent */
> setsockopt(skt, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
> XPRecv(skt, buf, 10); /* try to read some data to make sure */
> close(skt);
> }
>
> The shutdown call is key to fixing the problem. The XPRecv call is a
> non-blocking, call to recv with a short time out. This together with
> SO_LINGER ensures that an ack is received from the client before the
> connection is closed. I am not guaranteeing this code, but it works
> for me ...
>
> -- Dave Raggett <dsr@w3.org> tel: +1 (617) 258 5741 fax: +1 (617) 258 8682
> World Wide Web Consortium, 545 Technology Square, Cambridge, MA 02139
> url = http://www.w3.org/hypertext/WWW/People/Raggett/index.html
>
Re: tcp/ip shutdown problem (fwd) [ In reply to ]
It does, but unfortunately, it runs afoul of several buggy Unixes whose
TCP/IP stacks don't honor the timeout when trying to close a linger-ing
socket --- I *thought* Simon had a fix which somehow got correct behavior
while not setting linger at all, but if so, this isn't it.

(HP-UX at least has the bug very badly --- set linger on a socket, and a
process will hang forever trying to close it, even if it has already been
kill -9'ed as is trying to die).

rst