Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[0be611]: sighttpd-maxlistners.patch Maximize Restore History

Download this file

sighttpd-maxlistners.patch    122 lines (106 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
diff -rupN sighttpd/src/http-response.c sighttpd.mod/src/http-response.c
--- sighttpd/src/http-response.c 2012-06-15 18:00:02.188820357 +0200
+++ sighttpd.mod/src/http-response.c 2012-06-15 18:26:07.731116519 +0200
@@ -93,6 +93,12 @@ respond_method_not_allowed (const char *
}
static void
+respond_service_unavailable (const char ** status_line, params_t ** response_headers)
+{
+ *status_line = http_status_line (HTTP_STATUS_SERVICE_UNAVAILABLE);
+}
+
+static void
respond (struct sighttpd_child * schild, http_request * request, params_t * request_headers)
{
params_t * response_headers;
@@ -100,22 +106,25 @@ respond (struct sighttpd_child * schild,
response_headers = response_headers_new ();
- switch (request->method) {
- case HTTP_METHOD_HEAD:
- case HTTP_METHOD_GET:
- respond_get_head (schild, request, request_headers, &status_line, &response_headers);
- break;
- default:
- respond_method_not_allowed (&status_line, &response_headers);
- break;
- }
+ switch (request->method) {
+ case HTTP_METHOD_HEAD:
+ case HTTP_METHOD_GET:
+ if(schild->service_unavailable)
+ respond_service_unavailable (&status_line, &response_headers);
+ else
+ respond_get_head (schild, request, request_headers, &status_line, &response_headers);
+ break;
+ default:
+ respond_method_not_allowed (&status_line, &response_headers);
+ break;
+ }
write (schild->accept_fd, status_line, strlen(status_line));
params_writefd (schild->accept_fd, response_headers);
log_access (request, request_headers, response_headers);
- if (request->method == HTTP_METHOD_GET) {
+ if (request->method == HTTP_METHOD_GET && schild->service_unavailable == 0 ) {
respond_get_body (schild, request, request_headers);
}
diff -rupN sighttpd/src/sighttpd.c sighttpd.mod/src/sighttpd.c
--- sighttpd/src/sighttpd.c 2012-06-15 18:00:02.198820371 +0200
+++ sighttpd.mod/src/sighttpd.c 2012-06-15 18:02:16.449017281 +0200
@@ -26,6 +26,7 @@ struct sighttpd * sighttpd_init (struct
{
struct sighttpd * sighttpd;
const char *portname;
+ const char *max_listeners;
int port;
if ((sighttpd = malloc (sizeof(*sighttpd))) == NULL)
@@ -51,6 +52,15 @@ struct sighttpd * sighttpd_init (struct
port = atoi(portname);
}
+ max_listeners = dictionary_lookup (cfg->dictionary, "MaxListeners");
+ if (max_listeners == NULL) {
+ sighttpd->max_listeners = 0;
+ } else {
+ sighttpd->max_listeners = atoi(max_listeners);
+ }
+
+ sighttpd->cur_listeners = 0;
+
sighttpd->port = port;
sighttpd->resources = cfg->resources;
@@ -78,6 +88,13 @@ sighttpd_child_new (struct sighttpd * si
if ((schild = malloc (sizeof(*schild))) == NULL)
return NULL;
+ sighttpd->cur_listeners ++;
+
+ if( sighttpd->max_listeners > 0 && sighttpd->cur_listeners > sighttpd->max_listeners )
+ schild->service_unavailable = 1;
+ else
+ schild->service_unavailable = 0;
+
schild->sighttpd = sighttpd;
schild->accept_fd = accept_fd;
@@ -88,5 +105,8 @@ void
sighttpd_child_destroy (struct sighttpd_child * schild)
{
close (schild->accept_fd);
+ if( schild->sighttpd->cur_listeners > 0 )
+ schild->sighttpd->cur_listeners --;
+
free (schild);
}
diff -rupN sighttpd/src/sighttpd.h sighttpd.mod/src/sighttpd.h
--- sighttpd/src/sighttpd.h 2012-06-15 18:00:02.198820371 +0200
+++ sighttpd.mod/src/sighttpd.h 2012-06-15 17:59:23.288763297 +0200
@@ -7,11 +7,14 @@
struct sighttpd {
int port;
list_t * resources;
+ int cur_listeners;
+ int max_listeners;
};
struct sighttpd_child {
struct sighttpd * sighttpd;
int accept_fd;
+ int service_unavailable;
};
struct sighttpd * sighttpd_init (struct cfg * cfg);