Browse Source

added startup-time selectable network-backend

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@808 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.7
Jan Kneschke 16 years ago
parent
commit
e290b119db
  1. 2
      NEWS
  2. 2
      configure.in
  3. 10
      src/base.h
  4. 3
      src/configfile.c
  5. 14
      src/mod_fastcgi.c
  6. 13
      src/mod_proxy.c
  7. 14
      src/mod_scgi.c
  8. 5
      src/mod_status.c
  9. 103
      src/network.c
  10. 1
      src/server.c

2
NEWS

@ -11,13 +11,13 @@ NEWS
* added support for %I in mod_accesslog
* added better compat to Apache for ?auto in mod_status
* added support for userdirs without a entry in /etc/passwd in mod_userdir
* added startup-time selectable network-backend
* workaround missing client-bug by assuming we received a close-notify on
non-keep-alive requests in SSL request
* disabled kerberos5 support by default to fix compilation on RHEL
* fixed order of library checks to fix compilation on Solaris 9
* fixed open file-descriptors on read-error
* fixed crash if /var/tmp is not writable
* TODO: added startup-time selectable network-backend
* TODO: export location of upload-files to config as array
* TODO: add debugging to mod_webdav

2
configure.in

@ -470,7 +470,7 @@ if test "x$ac_cv_func_sendfile" = xyes; then
#include <errno.h>
int main() {
int o = 0;
if (-1 == sendfile(0, 0, &o, 0) && errno == ENOSYS) return -1;
if (-1 == sendfile(-1, 0, &o, 0) && errno == ENOSYS) return -1;
return 0;
} ],
AC_MSG_RESULT(yes),

10
src/base.h

@ -439,6 +439,7 @@ typedef struct {
buffer *event_handler;
buffer *modules_dir;
buffer *network_backend;
array *modules;
unsigned short max_worker;
@ -480,7 +481,7 @@ typedef struct {
size_t used;
} server_socket_array;
typedef struct {
typedef struct server {
server_socket_array srv_sockets;
/* the errorlog */
@ -556,6 +557,13 @@ typedef struct {
fdevent_handler_t event_handler;
int (* network_backend_write)(struct server *srv, connection *con, int fd, chunkqueue *cq);
int (* network_backend_read)(struct server *srv, connection *con, int fd, chunkqueue *cq);
#ifdef USE_OPENSSL
int (* network_ssl_backend_write)(struct server *srv, connection *con, SSL *ssl, chunkqueue *cq);
int (* network_ssl_backend_read)(struct server *srv, connection *con, SSL *ssl, chunkqueue *cq);
#endif
uid_t uid;
gid_t gid;
} server;

3
src/configfile.c

@ -77,6 +77,7 @@ static int config_insert(server *srv) {
{ "server.range-requests", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 40 */
{ "server.stat-cache-engine", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 41 */
{ "server.max-connections", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_SERVER }, /* 42 */
{ "server.network-backend", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 43 */
{ "server.host", "use server.bind instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
{ "server.docroot", "use server.document-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
@ -112,6 +113,7 @@ static int config_insert(server *srv) {
stat_cache_string = buffer_init();
cv[41].destination = stat_cache_string;
cv[43].destination = srv->srvconf.network_backend;
cv[42].destination = &(srv->srvconf.max_conns);
cv[12].destination = &(srv->srvconf.max_request_size);
@ -1030,6 +1032,7 @@ int config_set_defaults(server *srv) {
{ FDEVENT_HANDLER_UNSET, NULL }
};
if (buffer_is_empty(s->document_root)) {
log_error_write(srv, __FILE__, __LINE__, "s",
"a default document-root has to be set");

14
src/mod_fastcgi.c

@ -23,7 +23,6 @@
#include "inet_ntop_cache.h"
#include "stat_cache.h"
#include "network_backends.h"
#include <fastcgi.h>
#include <stdio.h>
@ -2707,18 +2706,7 @@ static handler_t fcgi_write_request(server *srv, handler_ctx *hctx) {
/* fall through */
case FCGI_STATE_WRITE:
#if defined USE_LINUX_SENDFILE
ret = network_write_chunkqueue_linuxsendfile(srv, con, hctx->fd, hctx->wb);
#elif defined USE_FREEBSD_SENDFILE
ret = network_write_chunkqueue_freebsdsendfile(srv, con, hctx->fd, hctx->wb);
#elif defined USE_SOLARIS_SENDFILEV
ret = network_write_chunkqueue_solarissendfilev(srv, con, hctx->fd, hctx->wb);
#elif defined USE_WRITEV
ret = network_write_chunkqueue_writev(srv, con, hctx->fd, hctx->wb);
#else
ret = network_write_chunkqueue_write(srv, con, hctx->fd, hctx->wb);
#endif
ret = srv->network_backend_write(srv, con, hctx->fd, hctx->wb);
chunkqueue_remove_finished_chunks(hctx->wb);

13
src/mod_proxy.c

@ -23,7 +23,6 @@
#include "inet_ntop_cache.h"
#include "crc32.h"
#include "network_backends.h"
#include <stdio.h>
@ -789,17 +788,7 @@ static handler_t proxy_write_request(server *srv, handler_ctx *hctx) {
/* fall through */
case PROXY_STATE_WRITE:;
#if defined USE_LINUX_SENDFILE
ret = network_write_chunkqueue_linuxsendfile(srv, con, hctx->fd, hctx->wb);
#elif defined USE_FREEBSD_SENDFILE
ret = network_write_chunkqueue_freebsdsendfile(srv, con, hctx->fd, hctx->wb);
#elif defined USE_SOLARIS_SENDFILEV
ret = network_write_chunkqueue_solarissendfilev(srv, con, hctx->fd, hctx->wb);
#elif defined USE_WRITEV
ret = network_write_chunkqueue_writev(srv, con, hctx->fd, hctx->wb);
#else
ret = network_write_chunkqueue_write(srv, con, hctx->fd, hctx->wb);
#endif
ret = srv->network_backend_write(srv, con, hctx->fd, hctx->wb);
chunkqueue_remove_finished_chunks(hctx->wb);

14
src/mod_scgi.c

@ -22,7 +22,6 @@
#include "plugin.h"
#include "inet_ntop_cache.h"
#include "network_backends.h"
#include <stdio.h>
@ -2257,18 +2256,7 @@ static handler_t scgi_write_request(server *srv, handler_ctx *hctx) {
/* fall through */
case FCGI_STATE_WRITE:
/* why aren't we using the network_ interface here ? */
#if defined USE_LINUX_SENDFILE
ret = network_write_chunkqueue_linuxsendfile(srv, con, hctx->fd, hctx->wb);
#elif defined USE_FREEBSD_SENDFILE
ret = network_write_chunkqueue_freebsdsendfile(srv, con, hctx->fd, hctx->wb);
#elif defined USE_SOLARIS_SENDFILEV
ret = network_write_chunkqueue_solarissendfilev(srv, con, hctx->fd, hctx->wb);
#elif defined USE_WRITEV
ret = network_write_chunkqueue_writev(srv, con, hctx->fd, hctx->wb);
#else
ret = network_write_chunkqueue_write(srv, con, hctx->fd, hctx->wb);
#endif
ret = srv->network_backend_write(srv, con, hctx->fd, hctx->wb);
chunkqueue_remove_finished_chunks(hctx->wb);

5
src/mod_status.c

@ -640,11 +640,6 @@ static handler_t mod_status_handle_server_config(server *srv, connection *con, v
mod_status_row_append(b, "Rewrite Engine", "enabled");
#else
mod_status_row_append(b, "Rewrite Engine", "disabled - pcre missing");
#endif
#ifdef HAVE_ZLIB_H
mod_status_row_append(b, "On-the-Fly Output Compression", "enabled");
#else
mod_status_row_append(b, "On-the-Fly Output Compression", "disabled - zlib missing");
#endif
mod_status_header_append(b, "Network Engine");

103
src/network.c

@ -369,9 +369,40 @@ int network_close(server *srv) {
return 0;
}
typedef enum {
NETWORK_BACKEND_UNSET,
NETWORK_BACKEND_WRITE,
NETWORK_BACKEND_WRITEV,
NETWORK_BACKEND_LINUX_SENDFILE,
NETWORK_BACKEND_FREEBSD_SENDFILE,
NETWORK_BACKEND_SOLARIS_SENDFILEV
} network_backend_t;
int network_init(server *srv) {
buffer *b;
size_t i;
network_backend_t backend;
struct nb_map {
network_backend_t nb;
const char *name;
} network_backends[] = {
/* lowest id wins */
#if defined USE_LINUX_SENDFILE
{ NETWORK_BACKEND_LINUX_SENDFILE, "linux-sendfile" },
#endif
#if defined USE_FREEBSD_SENDFILE
{ NETWORK_BACKEND_FREEBSD_SENDFILE, "freebsd-sendfile" },
#endif
#if defined USE_SOLARIS_SENDFILEV
{ NETWORK_BACKEND_SOLARIS_SENDFILEV, "solaris-sendfilev" },
#endif
#if defined USE_WRITEV
{ NETWORK_BACKEND_WRITEV, "writev" },
#endif
{ NETWORK_BACKEND_WRITE, "write" },
{ NETWORK_BACKEND_UNSET, NULL }
};
b = buffer_init();
@ -384,6 +415,61 @@ int network_init(server *srv) {
}
buffer_free(b);
#ifdef USE_OPENSSL
srv->network_ssl_backend_write = network_write_chunkqueue_openssl;
#endif
/* get a usefull default */
backend = network_backends[0].nb;
/* match name against known types */
if (!buffer_is_empty(srv->srvconf.network_backend)) {
for (i = 0; network_backends[i].name; i++) {
/**/
if (buffer_is_equal_string(srv->srvconf.network_backend, network_backends[i].name, strlen(network_backends[i].name))) {
backend = network_backends[i].nb;
break;
}
}
if (NULL == network_backends[i].name) {
/* we don't know it */
log_error_write(srv, __FILE__, __LINE__, "sb",
"server.network-backend has a unknown value:",
srv->srvconf.network_backend);
return -1;
}
}
switch(backend) {
case NETWORK_BACKEND_WRITE:
srv->network_backend_write = network_write_chunkqueue_write;
break;
#ifdef USE_WRITEV
case NETWORK_BACKEND_WRITEV:
srv->network_backend_write = network_write_chunkqueue_writev;
break;
#endif
#ifdef USE_LINUX_SENDFILE
case NETWORK_BACKEND_LINUX_SENDFILE:
srv->network_backend_write = network_write_chunkqueue_linuxsendfile;
break;
#endif
#ifdef USE_FREEBSD_SENDFILE
case NETWORK_BACKEND_FREEBSD_SENDFILE:
srv->network_backend_write = network_write_chunkqueue_freebsdsendfile;
break;
#endif
#ifdef USE_SOLARIS_SENDFILEV
case NETWORK_BACKEND_SOLARIS_SENDFILEV:
srv->network_backend_write = network_write_chunkqueue_solarissendfilev;
break;
#endif
default:
return -1;
}
/* check for $SERVER["socket"] */
for (i = 1; i < srv->config_context->used; i++) {
data_config *dc = (data_config *)srv->config_context->data[i];
@ -455,22 +541,9 @@ int network_write_chunkqueue(server *srv, connection *con, chunkqueue *cq) {
#endif
if (srv_socket->is_ssl) {
#ifdef USE_OPENSSL
ret = network_write_chunkqueue_openssl(srv, con, con->ssl, cq);
#endif
ret = srv->network_ssl_backend_write(srv, con, con->ssl, cq);
} else {
/* dispatch call */
#if defined USE_LINUX_SENDFILE
ret = network_write_chunkqueue_linuxsendfile(srv, con, con->fd, cq);
#elif defined USE_FREEBSD_SENDFILE
ret = network_write_chunkqueue_freebsdsendfile(srv, con, con->fd, cq);
#elif defined USE_SOLARIS_SENDFILEV
ret = network_write_chunkqueue_solarissendfilev(srv, con, con->fd, cq);
#elif defined USE_WRITEV
ret = network_write_chunkqueue_writev(srv, con, con->fd, cq);
#else
ret = network_write_chunkqueue_write(srv, con, con->fd, cq);
#endif
ret = srv->network_backend_write(srv, con, con->fd, cq);
}
if (ret >= 0) {

1
src/server.c

@ -164,6 +164,7 @@ static server *server_init(void) {
srv->srvconf.modules = array_init();
srv->srvconf.modules_dir = buffer_init_string(LIBRARY_DIR);
srv->srvconf.network_backend = buffer_init();
/* use syslog */
srv->errorlog_fd = -1;

Loading…
Cancel
Save