Mercurial > urweb
comparison src/c/fastcgi.c @ 863:305bc0a431de
.msgs processing in FastCGI
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sat, 27 Jun 2009 17:50:31 -0400 |
parents | 66dbf3953758 |
children | 6304f5e8fbb4 |
comparison
equal
deleted
inserted
replaced
862:66dbf3953758 | 863:305bc0a431de |
---|---|
111 | 111 |
112 static void on_failure(uw_context ctx) { | 112 static void on_failure(uw_context ctx) { |
113 uw_write_header(ctx, "Status: 500 Internal Server Error\r\n"); | 113 uw_write_header(ctx, "Status: 500 Internal Server Error\r\n"); |
114 } | 114 } |
115 | 115 |
116 static int write_stdout(void *data, char *buf, size_t len) { | 116 static int write_stdout(void *data, const char *buf, size_t len) { |
117 FCGI_Output *o = (FCGI_Output *)data; | 117 FCGI_Output *o = (FCGI_Output *)data; |
118 while (len > 0) { | 118 while (len > 0) { |
119 size_t len2 = len; | 119 size_t len2 = len; |
120 if (len2 > 65535) | 120 if (len2 > 65535) |
121 len2 = 65535; | 121 len2 = 65535; |
252 | 252 |
253 memcpy(nv->value, buf + nameLength, valueLength); | 253 memcpy(nv->value, buf + nameLength, valueLength); |
254 nv->value[valueLength] = 0; | 254 nv->value[valueLength] = 0; |
255 | 255 |
256 return 0; | 256 return 0; |
257 } | |
258 | |
259 static int fastcgi_close_with(FCGI_Output *out, request_result rr) { | |
260 FCGI_EndRequestBody *erb = (FCGI_EndRequestBody *)out->r.contentData; | |
261 | |
262 close_stream(out, FCGI_STDOUT); | |
263 close_stream(out, FCGI_STDERR); | |
264 | |
265 if (rr == SERVED) | |
266 erb->appStatusB3 = erb->appStatusB2 = erb->appStatusB1 = erb->appStatusB0 = 0; | |
267 else | |
268 erb->appStatusB3 = erb->appStatusB2 = erb->appStatusB1 = erb->appStatusB0 = 0xFF; | |
269 | |
270 erb->protocolStatus = FCGI_REQUEST_COMPLETE; | |
271 fastcgi_send(out, FCGI_END_REQUEST, sizeof(FCGI_EndRequestBody)); | |
272 return close(out->sock); | |
273 } | |
274 | |
275 static int fastcgi_close(int sock) { | |
276 FCGI_Output out; | |
277 out.sock = sock; | |
278 out.r.version = FCGI_VERSION_1; | |
279 out.r.paddingLength = 0; | |
280 out.r.reserved = 0; | |
281 | |
282 return fastcgi_close_with(&out, SERVED); | |
283 } | |
284 | |
285 int fastcgi_send_normal(int sock, const void *buf, ssize_t len) { | |
286 FCGI_Output out; | |
287 out.sock = sock; | |
288 out.r.version = FCGI_VERSION_1; | |
289 out.r.paddingLength = 0; | |
290 out.r.reserved = 0; | |
291 | |
292 return write_stdout(&out, buf, len); | |
257 } | 293 } |
258 | 294 |
259 static void *worker(void *data) { | 295 static void *worker(void *data) { |
260 int me = *(int *)data; | 296 int me = *(int *)data; |
261 FCGI_Input *in = fastcgi_input(); | 297 FCGI_Input *in = fastcgi_input(); |
409 | 445 |
410 uw_set_headers(ctx, get_header, &hs); | 446 uw_set_headers(ctx, get_header, &hs); |
411 | 447 |
412 { | 448 { |
413 request_result rr; | 449 request_result rr; |
414 FCGI_EndRequestBody *erb = (FCGI_EndRequestBody *)out->r.contentData; | |
415 | 450 |
416 rr = uw_request(rc, ctx, method, path, query_string, body, body_read, | 451 rr = uw_request(rc, ctx, method, path, query_string, body, body_read, |
417 on_success, on_failure, | 452 on_success, on_failure, |
418 out, log_error, log_debug, | 453 out, log_error, log_debug, |
419 in->sock); | 454 in->sock, fastcgi_send_normal, fastcgi_close); |
420 | 455 |
421 if (rr == KEEP_OPEN) | 456 if (rr == KEEP_OPEN) |
422 goto done2; | 457 goto done2; |
423 | 458 |
424 uw_output(ctx, write_stdout, out); | 459 uw_output(ctx, write_stdout, out); |
425 close_stream(out, FCGI_STDOUT); | 460 fastcgi_close_with(out, rr); |
426 close_stream(out, FCGI_STDERR); | 461 goto done2; |
427 | |
428 if (rr == SERVED) | |
429 erb->appStatusB3 = erb->appStatusB2 = erb->appStatusB1 = erb->appStatusB0 = 0; | |
430 else | |
431 erb->appStatusB3 = erb->appStatusB2 = erb->appStatusB1 = erb->appStatusB0 = 0xFF; | |
432 | |
433 erb->protocolStatus = FCGI_REQUEST_COMPLETE; | |
434 fastcgi_send(out, FCGI_END_REQUEST, sizeof(FCGI_EndRequestBody)); | |
435 } | 462 } |
436 | 463 |
437 done: | 464 done: |
438 close(in->sock); | 465 close(in->sock); |
439 done2: | 466 done2: |