On Thu, 2007-08-16 at 15:06 +0100, Denys Vlasenko wrote: > Hi people, > > In handle_incoming_and_exit() we used to do this > just before exit: > > /* Properly wait for remote to closed */ > int retval; > shutdown(accepted_socket, SHUT_WR); > do { > fd_set s_fd; > struct timeval tv; > FD_ZERO(&s_fd); > FD_SET(accepted_socket, &s_fd); > tv.tv_sec = 2; > tv.tv_usec = 0; > retval = select(accepted_socket + 1, &s_fd, NULL, NULL, &tv); > } while (retval > 0 && read(accepted_socket, iobuf, sizeof(iobuf) > 0)); Actually this looks like a bug ^^^^^^^^^^^^^^^^^ and the line should have been: } while (retval > 0 && read(accepted_socket, iobuf, sizeof(iobuf)) > 0); > shutdown(accepted_socket, SHUT_RD); > close(accepted_socket); > exit(0); > > Apparently we first inform peer that we are not going to write anything > anymore, and then we drain any remaining input. > > Question - why is this needed? What bad things can happen if we just exit(0) > without doing all this? The "shutdown(accepted_socket, SHUT_RD)" and "close(accepted_socket)" is superfluous since exit() closes all file descriptors anyway. The exit() (or a close() instead of the "shutdown(accepted_socket, SHUT_WR)") can produce an error on the sending side if there are byte left in some buffer there. And IE5/IE5.5 (I don't know about more recent IEs) delivered an confusing and misleading (IIRC) error window, if that happens. This was especially annoying (read: it happened pretty every time) since several versions had a bug where IE sent 2 more bytes than actually told the server in the HTTP request. Perhaps the above can be reduced by simply having a blocking read() and avoid the select(): ---- snip ---- while (read(accepted_socket, iobuf, sizeof(iobuf)) > 0) { /* do nothing */; } ---- snip ---- Bernd -- Firmix Software GmbH http://www.firmix.at/ mobil: +43 664 4416156 fax: +43 1 7890849-55 Embedded Linux Development and Services