clients.cxx

来自「PTypes (C++ Portable Types Library) is a」· CXX 代码 · 共 129 行

CXX
129
字号
/* * *  C++ Portable Types Library (PTypes) *  Version 1.7.5   Released 9-Mar-2003 * *  Copyright (c) 2001, 2002, 2003 Hovik Melikyan * *  http://www.melikyan.com/ptypes/ *  http://ptypes.sourceforge.net/ * */#include <pasync.h>#include "config.h"#include "log.h"#include "clients.h"USING_PTYPESthread_list  threads;int          thread_count;int          thread_seq;datetime     started;thread_list::thread_list(): lock(), count(0), list(0){}thread_list::~thread_list()  {    memfree(list);}void thread_list::set_capacity(int icount){    if (list != 0)        fatal(1001, "");    count = icount;    list = (client_thread**)memalloc(sizeof(client_thread*) * count);    memset(list, 0, sizeof(client_thread*) * count);}void thread_list::add(client_thread* t){    lock.lock();    int i;    for (i = 0; i < count; i++)        if (list[i] == 0)            break;    if (i == count)        fatal(1002, "");    list[i] = t;    lock.unlock();}void thread_list::del(client_thread* t){    lock.lock();    int i;    for (i = 0; i < count; i++)        if (list[i] == t)            break;    if (i == count)        fatal(1003, "");    list[i] = 0;    lock.unlock();}client_thread::client_thread(ipstream* iclient)    : thread(true),      request_rec(*iclient, *iclient, iclient->get_ip()),      client(iclient), seq_num(0){    pincrement(&thread_count);}void client_thread::cleanup(){    delete client;    threads.del(this);}client_thread::~client_thread(){    pdecrement(&thread_count);}void client_thread::execute(){    seq_num = pincrement(&thread_seq);    threads.add(this);    try    {        while (1)        {            request_rec::respond();            if (!client->get_active())                break;            if (!client->waitfor(DEF_KEEP_ALIVE_TIMEOUT))                break;            if (client->get_eof())                break;        }    }    catch(estream* e)    {        htlog_write(client_ip, req_line, rsp_code, sockout->tell() - hdr_size, referer);        client->close();        delete e;    }        client->close();}

⌨️ 快捷键说明

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