. Don't need to nonblock the listening socket.

. Use acceptfilter.
This commit is contained in:
Emil Mikulic 2003-11-18 11:00:08 +00:00
parent f0766d80f3
commit f7c0995234

View File

@ -302,6 +302,23 @@ static void nonblock_socket(const int sock)
/* ---------------------------------------------------------------------------
* Enable acceptfilter on the specified socket. (This is only available on
* FreeBSD)
*/
static void acceptfilter_socket(const int sock)
{
#ifdef __FreeBSD__
struct accept_filter_arg filt = {"httpready", ""};
if (setsockopt(sock, SOL_SOCKET, SO_ACCEPTFILTER,
&filt, sizeof(filt)) == -1)
fprintf(stderr, "Cannot enable acceptfilter: %s\n",
strerror(errno));
#endif
}
/* ---------------------------------------------------------------------------
* Split string out of src with range [left:right-1]
*/
@ -753,8 +770,6 @@ static void init_sockin(void)
&sockopt, sizeof(sockopt)) == -1)
err(1, "setsockopt(SO_REUSEADDR)");
nonblock_socket(sockin);
/* bind socket */
addrin.sin_family = (u_char)PF_INET;
addrin.sin_port = htons(bindport);
@ -769,6 +784,8 @@ static void init_sockin(void)
/* listen on socket */
if (listen(sockin, max_connections) == -1)
err(1, "listen()");
acceptfilter_socket(sockin);
}