📄 protocol.c
字号:
{ int len; int code; write_env(s, r); write_headers(s, r); // read post data if (ap_should_client_block(r)) { char buf[BUF_LENGTH]; int isFirst = 1; while ((len = ap_get_client_block(r, buf, BUF_LENGTH)) > 0) { ap_reset_timeout(r); if (! isFirst) { code = send_data(s, r, CSE_ACK, keepalive); if (code < 0 || code == CSE_END || code == CSE_CLOSE) break; } cse_write_packet(s, CSE_DATA, buf, len); isFirst = 0; } } if (! g_srun_keepalive) cse_write_packet(s, CSE_CLOSE, 0, 0); else cse_write_packet(s, CSE_END, 0, 0); code = send_data(s, r, CSE_END, keepalive); return code == CSE_END;}/** * Handle a request. */static intcaucho_request(request_rec *r){ config_t *config = cse_get_module_config(r->server); stream_t s; int retval; int keepalive = 0; int reuse; if ((retval = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR))) return retval; ap_soft_timeout("servlet request", r); if (open_connection(&s, r, config) < 0) { ap_kill_timeout(r); return OK; } reuse = write_request(&s, r, config, &keepalive); ap_kill_timeout(r); ap_rflush(r); if (reuse) cse_recycle(&s); else cse_close(&s, "request"); return OK;}/** * Print the statistics for each JVM. */static voidjvm_status(config_t *config, request_rec *r){ int i; stream_t s; int code; ap_rputs("<center><table border=2 cellspacing=0 cellpadding=2 width='60%'>\n", r); ap_rputs("<tr><th>Host\n", r); ap_rputs(" <th>Minute<br>%cpu/thread\n", r); ap_rputs(" <th>Hour<br>%cpu/thread\n", r); ap_rputs(" <th>Day<br>%cpu/thread\n", r); for (i = 0; i < config->srun_size; i++) { srun_t *srun = config->srun_list + i; int port = srun->port; ap_rputs("<tr>", r); if (! cse_open(&s, config, srun, r->pool, r->server)) { ap_rprintf(r, "<td bgcolor='#ff6666'>%s:%d%s</td><td colspan=3> ", srun->hostname ? srun->hostname : "localhost", port, srun->is_backup ? "*" : ""); } else { char buf[8193]; FILE *file; registry_t *reg; ap_rprintf(r, "<td bgcolor='#66ff66'>%s:%d%s</td>", srun->hostname ? srun->hostname : "localhost", port, srun->is_backup ? "*" : ""); if (1) { cse_recycle(&s); continue; } cse_write_string(&s, CSE_URI, "/servlet/com.caucho.server.http.AdminServlet/xml"); cse_write_string(&s, CSE_PROTOCOL, "HTTP/0.9"); cse_write_string(&s, CSE_END, ""); cse_write_string(&s, CSE_CLOSE, ""); code = cse_read_string(&s, buf, sizeof(buf)); cse_recycle(&s); unlink("/tmp/caucho.stat"); file = fopen("/tmp/caucho.stat", "w+"); if (! file) continue; fprintf(file, "%s\n", buf); fclose(file); reg = 0; file = fopen("/tmp/caucho.stat", "r"); config->pool = r->pool; if (file) { reg = cse_parse(file, config); fclose(file); } if (reg && (reg = cse_next_link(reg->first, "resin-stats"))) { registry_t *group; registry_t *data; group = cse_next_link(reg->first, "minute"); if (group && (data = cse_next_link(group->first, "cpu-usage"))) { double v = atof(data->value); ap_rprintf(r, "<td>%.2f", v); } else ap_rprintf(r, "<td>--"); if (group && (data = cse_next_link(group->first, "threads"))) { double v = atof(data->value); ap_rprintf(r, "/%.2f", v); } else ap_rprintf(r, "/--"); group = cse_next_link(reg->first, "hour"); if (group && (data = cse_next_link(group->first, "cpu-usage"))) { double v = atof(data->value); ap_rprintf(r, "<td>%.2f", v); } else ap_rprintf(r, "<td>--"); if (group && (data = cse_next_link(group->first, "threads"))) { double v = atof(data->value); ap_rprintf(r, "/%.2f", v); } else ap_rprintf(r, "/--"); group = cse_next_link(reg->first, "day"); if (group && (data = cse_next_link(group->first, "cpu-usage"))) { double v = atof(data->value); ap_rprintf(r, "<td>%.2f", v); } else ap_rprintf(r, "<td>--"); if (group && (data = cse_next_link(group->first, "threads"))) { double v = atof(data->value); ap_rprintf(r, "/%.2f", v); } else ap_rprintf(r, "/--"); } } ap_rputs("</tr>\n", r); } ap_rputs("</table></center>\n", r);}/** * Print a summary of the configuration so users can understand what's * going on. Ping the server to check that it's up. */static intcaucho_status(request_rec *r){ config_t *config = cse_get_module_config(r->server); location_t *loc; r->content_type = "text/html"; ap_soft_timeout("caucho status", r); if (r->header_only) { ap_kill_timeout(r); return OK; } ap_send_http_header(r); ap_rputs("<html><title>Status : Caucho Servlet Engine</title>\n", r); ap_rputs("<body bgcolor=white>\n", r); ap_rputs("<h1>Status : Caucho Servlet Engine</h1>\n", r); jvm_status(config, r); ap_rputs("<p><center><table border=2 cellspacing=0 cellpadding=2 width='60%'>\n", r); ap_rputs("<tr><th width='50%'>Host\n", r); ap_rputs(" <th>url-pattern\n", r); loc = config ? config->locations : 0; for (; loc; loc = loc->next) { ap_rprintf(r, "<tr bgcolor='#ffcc66'><td>%s<td>%s%s%s%s</tr>\n", loc->host && loc->host[0] ? loc->host : "*", loc->prefix, ! loc->is_exact && ! loc->suffix ? "/*" : loc->suffix && loc->prefix[0] ? "/" : "", loc->suffix ? "*" : "", loc->suffix ? loc->suffix : ""); } ap_rputs("</table></center>\n", r); ap_rputs("</body></html>\n", r); ap_kill_timeout(r); return OK;}/** * When a child process starts, clear the srun structure so it doesn't * mistakenly think the old sockets areopen. */static voidcse_open_child(server_rec *server, pool *p){ config_t *config = cse_get_module_config(server); int i; cse_log("open child\n"); for (i = 0; i < config->srun_size; i++) { srun_t *srun = config->srun_list + i; srun->open_sock = -1; srun->sock = -1; srun->is_dead = 0; srun->last_time = 0; }}static voidcse_close_child(server_rec *server, pool *p){ config_t *config = cse_get_module_config(server); int i; cse_log("close child\n"); for (i = 0; i < config->srun_size; i++) { srun_t *srun = config->srun_list + i; if (srun->open_sock >= 0) { close(srun->open_sock); srun->open_sock = -1; } if (srun->sock >= 0) { close(srun->open_sock); srun->open_sock = -1; } }}/* * Only needed configuration is pointer to resin.conf */static command_rec caucho_commands[] = { {"CauchoConfigFile", cse_config_file_command, NULL, RSRC_CONF, TAKE1, "Pointer to the Caucho configuration file."}, {"CauchoHost", cse_host_command, NULL, RSRC_CONF, TAKE12, "Servlet runner host."}, {"CauchoBackup", cse_backup_command, NULL, RSRC_CONF, TAKE12, "Servlet runner backup."}, {"CauchoKeepalive", cse_keepalive_command, NULL, RSRC_CONF, FLAG, "keeps srun connections alive."}, {"CauchoErrorPage", cse_error_page_command, NULL, RSRC_CONF, TAKE1, "Error page when connections fail."}, {NULL}};/* * Caucho right has two content handlers: * caucho-status: summary information for debugging * caucho-request: dispatch a Caucho request */static const handler_rec caucho_handlers[] ={ {"caucho-status", caucho_status}, {"caucho-request", caucho_request}, {NULL}};/* * module configuration */module caucho_module ={ STANDARD_MODULE_STUFF, cse_module_init, /* module initializer */ NULL, /* per-directory config creator */ NULL, /* dir config merger */ cse_create_server_config, /* server config creator */ NULL, /* server config merger */ caucho_commands, /* command table */ caucho_handlers, /* [7] list of handlers */ NULL, /* [2] filename-to-URI translation */ NULL, /* [5] check/validate user_id */ NULL, /* [6] check user_id is valid *here* */ NULL, /* [4] check access by host address */ cse_dispatch, /* [7] MIME type checker/setter */ NULL, /* [8] fixups */ NULL, /* [10] logger */ NULL, /* [3] header parser */#if MODULE_MAGIC_NUMBER > 19970719 cse_open_child, /* apache child process init */ cse_close_child, /* apache child process exit/cleanup */ NULL /* [1] post read_request handling */#endif};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -