Changeset 37f5a09eba7361266c79ca6fdecd3851336934c8
- Timestamp:
- 04/07/10 02:18:29
(3 years ago)
- Author:
- Theo Schlossnagle <jesus@omniti.com>
- git-committer:
- Theo Schlossnagle <jesus@omniti.com> 1270606709 +0000
- git-parent:
[1aca1b7f24f7ddd3bb8e44f598a9e0500025d82f]
- git-author:
- Theo Schlossnagle <jesus@omniti.com> 1270606709 +0000
- Message:
pass the acceptor_closure into the noit_http context so we can print out something like common log format
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rd1eed0a |
r37f5a09 |
|
| 245 | 245 | len, len, b->buff + b->start + ctx->res.output_raw_offset); |
|---|
| 246 | 246 | ctx->res.output_raw_offset += len; |
|---|
| | 247 | ctx->res.bytes_written += len; |
|---|
| 247 | 248 | tlen += len; |
|---|
| 248 | 249 | goto choose_bucket; |
|---|
| … | … | |
| 258 | 259 | if(!req->current_input) req->current_input = req->first_input; |
|---|
| 259 | 260 | if(!req->current_input) return noit_false; |
|---|
| | 261 | if(req->start_time.tv_sec == 0) gettimeofday(&req->start_time, NULL); |
|---|
| 260 | 262 | restart: |
|---|
| 261 | 263 | while(req->current_input->prev && |
|---|
| … | … | |
| 677 | 679 | return mask | maybe_write_mask; |
|---|
| 678 | 680 | } |
|---|
| 679 | | noitL(http_access, "HTTP start request (%s)\n", ctx->req.uri_str); |
|---|
| | 681 | noitL(http_debug, "HTTP start request (%s)\n", ctx->req.uri_str); |
|---|
| 680 | 682 | } |
|---|
| 681 | 683 | |
|---|
| … | … | |
| 714 | 716 | |
|---|
| 715 | 717 | noit_http_session_ctx * |
|---|
| 716 | | noit_http_session_ctx_new(noit_http_dispatch_func f, void *c, eventer_t e) { |
|---|
| | 718 | noit_http_session_ctx_new(noit_http_dispatch_func f, void *c, eventer_t e, |
|---|
| | 719 | acceptor_closure_t *ac) { |
|---|
| 717 | 720 | noit_http_session_ctx *ctx; |
|---|
| 718 | 721 | ctx = calloc(1, sizeof(*ctx)); |
|---|
| … | … | |
| 723 | 726 | ctx->dispatcher_closure = c; |
|---|
| 724 | 727 | ctx->drive = noit_http_session_drive; |
|---|
| | 728 | ctx->ac = ac; |
|---|
| 725 | 729 | return ctx; |
|---|
| 726 | 730 | } |
|---|
| … | … | |
| 1042 | 1046 | noit_boolean |
|---|
| 1043 | 1047 | noit_http_response_end(noit_http_session_ctx *ctx) { |
|---|
| 1044 | | if(ctx->res.output) |
|---|
| 1045 | | noitL(http_access, "HTTP finished request (%s)\n", ctx->req.uri_str); |
|---|
| | 1048 | if(ctx->res.output) { |
|---|
| | 1049 | char ip[64], timestr[64]; |
|---|
| | 1050 | double time_ms; |
|---|
| | 1051 | struct tm *tm, tbuf; |
|---|
| | 1052 | time_t now; |
|---|
| | 1053 | struct timeval end_time, diff; |
|---|
| | 1054 | |
|---|
| | 1055 | gettimeofday(&end_time, NULL); |
|---|
| | 1056 | now = end_time.tv_sec; |
|---|
| | 1057 | tm = gmtime_r(&now, &tbuf); |
|---|
| | 1058 | strftime(timestr, sizeof(timestr), "%d/%b/%Y:%H:%M:%S -0000", tm); |
|---|
| | 1059 | sub_timeval(end_time, ctx->req.start_time, &diff); |
|---|
| | 1060 | time_ms = diff.tv_sec * 1000 + diff.tv_usec / 1000; |
|---|
| | 1061 | noit_convert_sockaddr_to_buff(ip, sizeof(ip), &ctx->ac->remote.remote_addr); |
|---|
| | 1062 | noitL(http_access, "%s - - [%s] \"%s %s %s\" %d %llu %.3f\n", |
|---|
| | 1063 | ip, timestr, |
|---|
| | 1064 | ctx->req.method_str, ctx->req.uri_str, ctx->req.protocol_str, |
|---|
| | 1065 | ctx->res.status_code, |
|---|
| | 1066 | (long long unsigned)ctx->res.bytes_written, |
|---|
| | 1067 | time_ms); |
|---|
| | 1068 | } |
|---|
| | 1069 | ctx->res.bytes_written = 0; |
|---|
| | 1070 | ctx->req.start_time.tv_sec = 0L; |
|---|
| 1046 | 1071 | if(!noit_http_response_flush(ctx, noit_true)) return noit_false; |
|---|
| 1047 | 1072 | return noit_true; |
|---|
| rd1eed0a |
r37f5a09 |
|
| 39 | 39 | #include "utils/noit_hash.h" |
|---|
| 40 | 40 | #include "utils/noit_atomic.h" |
|---|
| | 41 | #include "noit_listener.h" |
|---|
| 41 | 42 | |
|---|
| 42 | 43 | typedef enum { |
|---|
| … | … | |
| 96 | 97 | noit_hash_table headers; |
|---|
| 97 | 98 | noit_boolean complete; |
|---|
| | 99 | struct timeval start_time; |
|---|
| 98 | 100 | } noit_http_request; |
|---|
| 99 | 101 | |
|---|
| … | … | |
| 114 | 116 | noit_boolean closed; /* set by _end() */ |
|---|
| 115 | 117 | noit_boolean complete; /* complete, drained and disposable */ |
|---|
| | 118 | size_t bytes_written; /* tracks total bytes written */ |
|---|
| 116 | 119 | } noit_http_response; |
|---|
| 117 | 120 | |
|---|
| … | … | |
| 128 | 131 | void *dispatcher_closure; |
|---|
| 129 | 132 | eventer_func_t drive; |
|---|
| | 133 | acceptor_closure_t *ac; |
|---|
| 130 | 134 | } noit_http_session_ctx; |
|---|
| 131 | 135 | |
|---|
| 132 | 136 | API_EXPORT(noit_http_session_ctx *) |
|---|
| 133 | | noit_http_session_ctx_new(noit_http_dispatch_func, void *, eventer_t); |
|---|
| | 137 | noit_http_session_ctx_new(noit_http_dispatch_func, void *, eventer_t, |
|---|
| | 138 | acceptor_closure_t *); |
|---|
| 134 | 139 | API_EXPORT(void) |
|---|
| 135 | 140 | noit_http_session_ctx_release(noit_http_session_ctx *); |
|---|
| rbf43de9 |
r37f5a09 |
|
| 489 | 489 | } |
|---|
| 490 | 490 | |
|---|
| | 491 | int |
|---|
| | 492 | noit_convert_sockaddr_to_buff(char *buff, int blen, struct sockaddr *remote) { |
|---|
| | 493 | char name[128] = ""; |
|---|
| | 494 | buff[0] = '\0'; |
|---|
| | 495 | if(remote) { |
|---|
| | 496 | int len = 0; |
|---|
| | 497 | switch(remote->sa_family) { |
|---|
| | 498 | case AF_INET: |
|---|
| | 499 | len = sizeof(struct sockaddr_in); |
|---|
| | 500 | inet_ntop(remote->sa_family, &((struct sockaddr_in *)remote)->sin_addr, |
|---|
| | 501 | name, len); |
|---|
| | 502 | break; |
|---|
| | 503 | case AF_INET6: |
|---|
| | 504 | len = sizeof(struct sockaddr_in6); |
|---|
| | 505 | inet_ntop(remote->sa_family, &((struct sockaddr_in6 *)remote)->sin6_addr, |
|---|
| | 506 | name, len); |
|---|
| | 507 | break; |
|---|
| | 508 | case AF_UNIX: |
|---|
| | 509 | len = SUN_LEN(((struct sockaddr_un *)remote)); |
|---|
| | 510 | snprintf(name, sizeof(name), "%s", ((struct sockaddr_un *)remote)->sun_path); |
|---|
| | 511 | break; |
|---|
| | 512 | default: return 0; |
|---|
| | 513 | } |
|---|
| | 514 | } |
|---|
| | 515 | strlcpy(buff, name, blen); |
|---|
| | 516 | return strlen(buff); |
|---|
| | 517 | } |
|---|
| | 518 | |
|---|
| 491 | 519 | void |
|---|
| 492 | 520 | noit_listener_init(const char *toplevel) { |
|---|
| rb9a4230 |
r37f5a09 |
|
| 85 | 85 | noit_control_dispatch(eventer_t, int, void *, struct timeval *); |
|---|
| 86 | 86 | |
|---|
| | 87 | API_EXPORT(int) |
|---|
| | 88 | noit_convert_sockaddr_to_buff(char *, int, struct sockaddr *); |
|---|
| | 89 | |
|---|
| 87 | 90 | API_EXPORT(noit_hash_table *) |
|---|
| 88 | 91 | noit_listener_commands(); |
|---|
| rd1eed0a |
r37f5a09 |
|
| 321 | 321 | restc->http_ctx = |
|---|
| 322 | 322 | noit_http_session_ctx_new(noit_rest_request_dispatcher, |
|---|
| 323 | | restc, e); |
|---|
| | 323 | restc, e, ac); |
|---|
| 324 | 324 | |
|---|
| 325 | 325 | switch(ac->cmd) { |
|---|
| … | … | |
| 367 | 367 | restc->http_ctx = |
|---|
| 368 | 368 | noit_http_session_ctx_new(noit_rest_request_dispatcher, |
|---|
| 369 | | restc, e); |
|---|
| | 369 | restc, e, ac); |
|---|
| 370 | 370 | } |
|---|
| 371 | 371 | return restc->http_ctx->drive(e, mask, restc->http_ctx, now); |
|---|
| r4c3718f |
r37f5a09 |
|
| 205 | 205 | pthread_mutex_t storagenode_to_info_cache_lock; |
|---|
| 206 | 206 | noit_hash_table storagenode_to_info_cache; |
|---|
| 207 | | |
|---|
| 208 | | int |
|---|
| 209 | | convert_sockaddr_to_buff(char *buff, int blen, struct sockaddr *remote) { |
|---|
| 210 | | char name[128] = ""; |
|---|
| 211 | | buff[0] = '\0'; |
|---|
| 212 | | if(remote) { |
|---|
| 213 | | int len = 0; |
|---|
| 214 | | switch(remote->sa_family) { |
|---|
| 215 | | case AF_INET: |
|---|
| 216 | | len = sizeof(struct sockaddr_in); |
|---|
| 217 | | inet_ntop(remote->sa_family, &((struct sockaddr_in *)remote)->sin_addr, |
|---|
| 218 | | name, len); |
|---|
| 219 | | break; |
|---|
| 220 | | case AF_INET6: |
|---|
| 221 | | len = sizeof(struct sockaddr_in6); |
|---|
| 222 | | inet_ntop(remote->sa_family, &((struct sockaddr_in6 *)remote)->sin6_addr, |
|---|
| 223 | | name, len); |
|---|
| 224 | | break; |
|---|
| 225 | | case AF_UNIX: |
|---|
| 226 | | len = SUN_LEN(((struct sockaddr_un *)remote)); |
|---|
| 227 | | snprintf(name, sizeof(name), "%s", ((struct sockaddr_un *)remote)->sun_path); |
|---|
| 228 | | break; |
|---|
| 229 | | default: return 0; |
|---|
| 230 | | } |
|---|
| 231 | | } |
|---|
| 232 | | strlcpy(buff, name, blen); |
|---|
| 233 | | return strlen(buff); |
|---|
| 234 | | } |
|---|
| 235 | 207 | |
|---|
| 236 | 208 | /* Thread-safe connection pools */ |
|---|
| … | … | |
| 1248 | 1220 | const char *fqdn = fqdn_in ? fqdn_in : "default"; |
|---|
| 1249 | 1221 | |
|---|
| 1250 | | convert_sockaddr_to_buff(remote_str, sizeof(remote_str), remote); |
|---|
| | 1222 | noit_convert_sockaddr_to_buff(remote_str, sizeof(remote_str), remote); |
|---|
| 1251 | 1223 | if(!*remote_str) strlcpy(remote_str, "default", sizeof(remote_str)); |
|---|
| 1252 | 1224 | |
|---|