⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_wstat.cxx

📁 PTypes是一个扩充了多线程和网络功能的STL库
💻 CXX
字号:
/* * *  C++ Portable Types Library (PTypes) *  Version 2.0.2  Released 17-May-2004 * *  Copyright (C) 2001-2004 Hovik Melikyan * *  http://www.melikyan.com/ptypes/ * */#include "config.h"#include "utils.h"#include "request.h"#include "clients.h"const char* stat_str[STAT_MAX] = {"READ   ", "WRITE  ", "WAIT   "};static ipaddress localhost(127, 0, 0, 1);static void show_lifetime(outstm* sockout, datetime t){    datetime diff = now() - t;    int d = days(diff);    if (d > 0)        sockout->putf("%dd ", d);    sockout->put(dttostring(diff, "%H:%M:%S"));}void handle_wstat(request_rec& req){    // only requests from localhost are allowed    if (req.client_ip != localhost)        req.rsp_forbidden();    req.keep_alive = false;    req.begin_response(200, "OK");        if (req.method == HTTP_GET)     // not HEAD        req.put_content_type("text/html");    req.end_headers();    std_html_header(*req.sockout, "wshare status report");    req.sockout->put("<pre>\n");    req.sockout->putf("  Requests: %d\n", thread_seq);    req.sockout->put("  Running: ");    show_lifetime(req.sockout, ::started);    req.sockout->put("\n\n");    req.sockout->put("  Client          Status Lifetime  Request\n");    req.sockout->put("<hr noshade size=1>\n");    for (int i = 0; i < threads.count; i++)    {        if (threads.list[i] == 0)            continue;        // copy all parameters to local vars to free the thread_list mutex earlier        ipaddress tclient_ip = 0;        req_stat_t tstat = STAT_READ;        datetime tstarted = invdatetime;        string treq_line;        {            scoperead _lock(threads.lock);            client_thread* t = threads.list[i];            if (t != 0)            {                tclient_ip = t->client_ip;                tstat = t->stat;                tstarted = t->started;                treq_line = t->req_line;            }        }        if (tclient_ip == 0)            continue;        req.sockout->putf("  %-15s %s", pconst(iptostring(tclient_ip)), stat_str[tstat]);        show_lifetime(req.sockout, tstarted);        req.sockout->put("  ");        html_encode(*req.sockout, treq_line);        req.sockout->put("\n");    }    req.sockout->put("</pre>\n");    std_html_footer(*req.sockout);    req.end_response();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -