One bufferevent can be shared by file and fcgi.
authorreyk <reyk@openbsd.org>
Thu, 31 Jul 2014 14:25:14 +0000 (14:25 +0000)
committerreyk <reyk@openbsd.org>
Thu, 31 Jul 2014 14:25:14 +0000 (14:25 +0000)
usr.sbin/httpd/httpd.h
usr.sbin/httpd/server.c
usr.sbin/httpd/server_fcgi.c
usr.sbin/httpd/server_file.c

index 0b11fcf..fe6e0eb 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: httpd.h,v 1.23 2014/07/31 14:18:38 reyk Exp $ */
+/*     $OpenBSD: httpd.h,v 1.24 2014/07/31 14:25:14 reyk Exp $ */
 
 /*
  * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -254,8 +254,7 @@ struct client {
        void                    *clt_desc;
 
        int                      clt_fd;
-       struct bufferevent      *clt_file;
-       struct bufferevent      *clt_fcgi;
+       struct bufferevent      *clt_srvbev;
 
        off_t                    clt_toread;
        size_t                   clt_headerlen;
index 4c2645d..066596d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: server.c,v 1.17 2014/07/30 13:49:48 reyk Exp $        */
+/*     $OpenBSD: server.c,v 1.18 2014/07/31 14:25:14 reyk Exp $        */
 
 /*
  * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -600,8 +600,8 @@ server_close(struct client *clt, const char *msg)
        event_del(&clt->clt_ev);
        if (clt->clt_bev != NULL)
                bufferevent_disable(clt->clt_bev, EV_READ|EV_WRITE);
-       if (clt->clt_file != NULL)
-               bufferevent_disable(clt->clt_file, EV_READ|EV_WRITE);
+       if (clt->clt_srvbev != NULL)
+               bufferevent_disable(clt->clt_srvbev, EV_READ|EV_WRITE);
 
        if ((env->sc_opts & HTTPD_OPT_LOGUPDATE) && msg != NULL) {
                memset(&ibuf, 0, sizeof(ibuf));
@@ -625,8 +625,8 @@ server_close(struct client *clt, const char *msg)
        if (clt->clt_output != NULL)
                evbuffer_free(clt->clt_output);
 
-       if (clt->clt_file != NULL)
-               bufferevent_free(clt->clt_file);
+       if (clt->clt_srvbev != NULL)
+               bufferevent_free(clt->clt_srvbev);
        if (clt->clt_fd != -1)
                close(clt->clt_fd);
        if (clt->clt_s != -1)
index 79a2131..391d0d4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: server_fcgi.c,v 1.2 2014/07/31 14:18:38 reyk Exp $    */
+/*     $OpenBSD: server_fcgi.c,v 1.3 2014/07/31 14:25:14 reyk Exp $    */
 
 /*
  * Copyright (c) 2014 Florian Obser <florian@openbsd.org>
@@ -73,13 +73,13 @@ struct fcgi_record_header {
        uint16_t        content_len;
        uint8_t         padding_len;
        uint8_t         reserved;
-}__packed;
+} __packed;
 
 struct fcgi_begin_request_body {
        uint16_t        role;
        uint8_t         flags;
        uint8_t         reserved[5];
-}__packed;
+} __packed;
 
 void   server_fcgi_read(struct bufferevent *, void *);
 void   server_fcgi_error(struct bufferevent *, short, void *);
@@ -116,17 +116,17 @@ server_fcgi(struct httpd *env, struct client *clt)
        if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1)
                goto fail;
 
-       if (clt->clt_fcgi != NULL)
-               bufferevent_free(clt->clt_fcgi);
-       clt->clt_fcgi = bufferevent_new(fd, server_fcgi_read,
+       if (clt->clt_srvbev != NULL)
+               bufferevent_free(clt->clt_srvbev);
+       clt->clt_srvbev = bufferevent_new(fd, server_fcgi_read,
            NULL, server_fcgi_error, clt);
-       if (clt->clt_fcgi == NULL) {
+       if (clt->clt_srvbev == NULL) {
                errstr = "failed to allocate fcgi buffer event";
                goto fail;
        }
-       bufferevent_settimeout(clt->clt_fcgi,
+       bufferevent_settimeout(clt->clt_srvbev,
            srv_conf->timeout.tv_sec, srv_conf->timeout.tv_sec);
-       bufferevent_enable(clt->clt_fcgi, EV_READ);
+       bufferevent_enable(clt->clt_srvbev, EV_READ);
 
        bzero(&buf, sizeof(buf));
 
@@ -141,7 +141,7 @@ server_fcgi(struct httpd *env, struct client *clt)
            fcgi_record_header)];
        begin->role = htons(FCGI_RESPONDER);
 
-       bufferevent_write(clt->clt_fcgi, &buf,
+       bufferevent_write(clt->clt_srvbev, &buf,
            sizeof(struct fcgi_record_header) +
            sizeof(struct fcgi_begin_request_body));
 
@@ -158,18 +158,18 @@ server_fcgi(struct httpd *env, struct client *clt)
        
        h->content_len = htons(total_len);
 
-       bufferevent_write(clt->clt_fcgi, &buf,
+       bufferevent_write(clt->clt_srvbev, &buf,
            sizeof(struct fcgi_record_header) +
            ntohs(h->content_len));
 
        h->content_len = 0;
 
-       bufferevent_write(clt->clt_fcgi, &buf,
+       bufferevent_write(clt->clt_srvbev, &buf,
            sizeof(struct fcgi_record_header));
 
        h->type = FCGI_STDIN;
 
-       bufferevent_write(clt->clt_fcgi, &buf,
+       bufferevent_write(clt->clt_srvbev, &buf,
            sizeof(struct fcgi_record_header));
 
        return (0);
index e2887af..035c708 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: server_file.c,v 1.20 2014/07/31 13:28:15 reyk Exp $   */
+/*     $OpenBSD: server_file.c,v 1.21 2014/07/31 14:25:14 reyk Exp $   */
 
 /*
  * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -184,19 +184,19 @@ server_file(struct httpd *env, struct client *clt)
        }
 
        clt->clt_fd = fd;
-       if (clt->clt_file != NULL)
-               bufferevent_free(clt->clt_file);
+       if (clt->clt_srvbev != NULL)
+               bufferevent_free(clt->clt_srvbev);
 
-       clt->clt_file = bufferevent_new(clt->clt_fd, server_read,
+       clt->clt_srvbev = bufferevent_new(clt->clt_fd, server_read,
            server_write, server_file_error, clt);
-       if (clt->clt_file == NULL) {
+       if (clt->clt_srvbev == NULL) {
                errstr = "failed to allocate file buffer event";
                goto fail;
        }
 
-       bufferevent_settimeout(clt->clt_file,
+       bufferevent_settimeout(clt->clt_srvbev,
            srv_conf->timeout.tv_sec, srv_conf->timeout.tv_sec);
-       bufferevent_enable(clt->clt_file, EV_READ);
+       bufferevent_enable(clt->clt_srvbev, EV_READ);
        bufferevent_disable(clt->clt_bev, EV_READ);
 
        return (0);