From 151a32cf024f0ba82b9dc2d8c50846d6f805445e Mon Sep 17 00:00:00 2001 From: reyk Date: Thu, 31 Jul 2014 14:25:14 +0000 Subject: [PATCH] One bufferevent can be shared by file and fcgi. --- usr.sbin/httpd/httpd.h | 5 ++--- usr.sbin/httpd/server.c | 10 +++++----- usr.sbin/httpd/server_fcgi.c | 26 +++++++++++++------------- usr.sbin/httpd/server_file.c | 14 +++++++------- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/usr.sbin/httpd/httpd.h b/usr.sbin/httpd/httpd.h index 0b11fcf5f1b..fe6e0eb51db 100644 --- a/usr.sbin/httpd/httpd.h +++ b/usr.sbin/httpd/httpd.h @@ -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 @@ -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; diff --git a/usr.sbin/httpd/server.c b/usr.sbin/httpd/server.c index 4c2645d7833..066596d2522 100644 --- a/usr.sbin/httpd/server.c +++ b/usr.sbin/httpd/server.c @@ -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 @@ -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) diff --git a/usr.sbin/httpd/server_fcgi.c b/usr.sbin/httpd/server_fcgi.c index 79a21316006..391d0d4908b 100644 --- a/usr.sbin/httpd/server_fcgi.c +++ b/usr.sbin/httpd/server_fcgi.c @@ -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 @@ -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); diff --git a/usr.sbin/httpd/server_file.c b/usr.sbin/httpd/server_file.c index e2887af73ee..035c7088b7d 100644 --- a/usr.sbin/httpd/server_file.c +++ b/usr.sbin/httpd/server_file.c @@ -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 @@ -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); -- 2.20.1