]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
http_send.c: Minor post_select() cleanups.
authorAndre Noll <maan@systemlinux.org>
Mon, 4 Feb 2008 20:11:58 +0000 (21:11 +0100)
committerAndre Noll <maan@systemlinux.org>
Mon, 4 Feb 2008 20:11:58 +0000 (21:11 +0100)
Defer allocating memory for the client until
we will accept it.

http_send.c

index ce2fd09c45ac71215dda23370b73faaf75fb8dc6..63bfec03c9d1cd17ac4b34a7609c32c28c218ead 100644 (file)
@@ -98,7 +98,7 @@ static void http_send(long unsigned current_chunk,
 
 static void http_post_select(fd_set *rfds, __a_unused fd_set *wfds)
 {
-       int ret, match;
+       int ret, fd, match;
        struct sender_client *sc, *tmp;
        struct private_http_sender_data *phsd;
 
@@ -138,38 +138,38 @@ static void http_post_select(fd_set *rfds, __a_unused fd_set *wfds)
                PARA_ERROR_LOG("%s\n", para_strerror(-ret));
                return;
        }
-       sc = para_calloc(sizeof(*sc));
-       sc->fd = ret;
-       sc->name = make_message("%s", remote_name(sc->fd));
-       PARA_NOTICE_LOG("connection from %s (fd %d)\n", sc->name, sc->fd);
+       fd = ret;
        ret = -E_MAX_CLIENTS;
        if (conf.http_max_clients_arg > 0 && numclients >=
                        conf.http_max_clients_arg) {
                goto err_out;
        }
-       match = acl_lookup(sc->fd, &http_acl);
+       ret = mark_fd_nonblocking(fd);
+       if (ret < 0)
+               goto err_out;
+       match = acl_lookup(fd, &http_acl);
        PARA_DEBUG_LOG("acl lookup returned %d\n", match);
        ret = -E_ACL_PERM;
        if ((match && !conf.http_default_deny_given) ||
                        (!match && conf.http_default_deny_given))
                goto err_out;
-       ret = mark_fd_nonblocking(sc->fd);
-       if (ret < 0)
-               goto err_out;
+       numclients++;
+       sc = para_calloc(sizeof(*sc));
+       sc->fd = fd;
+       sc->name = make_message("%s", remote_name(fd));
+       PARA_NOTICE_LOG("connection from %s (fd %d)\n", sc->name, fd);
        phsd = para_malloc(sizeof(*phsd));
        sc->private_data = phsd;
        phsd->status = HTTP_CONNECTED;
        sc->cq = cq_new(MAX_BACKLOG);
-       numclients++;
        PARA_INFO_LOG("accepted client #%d: %s (fd %d)\n", numclients,
-               sc->name, sc->fd);
+               sc->name, fd);
        para_list_add(&sc->node, &clients);
-       add_close_on_fork_list(sc->fd);
+       add_close_on_fork_list(fd);
        return;
 err_out:
        PARA_WARNING_LOG("%s\n", para_strerror(-ret));
-       close(sc->fd);
-       free(sc);
+       close(fd);
 }
 
 static void http_pre_select(int *max_fileno, fd_set *rfds, __a_unused fd_set *wfds)