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

📄 clients.cxx

📁 PTypes (C++ Portable Types Library) is a simple alternative to the STL that includes multithreading
💻 CXX
字号:
/* * *  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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -