Mysterious code in httpd.c

Denys Vlasenko vda.linux at googlemail.com
Thu Aug 16 14:06:26 UTC 2007


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));
        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?

For the time being, I commented it out.
--
vda



More information about the busybox mailing list