qinguoyi / TinyWebServer

:fire: Linux下C++轻量级WebServer服务器
Apache License 2.0
15.8k stars 3.8k forks source link

线程池 threadpool<T>::run() 函数中,为什么要判断 request 非NULL? #275

Closed arglone closed 1 month ago

arglone commented 1 month ago

我想不到任何一种情况会导致 requestNULL,也就是下面的代码我觉得是没必要的:

    if (!request)
        continue;

threadpool<T>::run() 用的 request 最先是 WebServer::dealwithwrite()WebServer::dealwithread()append 操作进来的。append 是类似 m_pool->append(users + sockfd, 1); 这样直接操作的 users 数组。但是我们看到 WebServer::WebServer() 构造函数内是直接 users = new http_conn[MAX_FD]; 的,因此 users + sockfd 在任何时候都不可能为NULL。即使 WebServer::~WebServer() 析构函数内做了 delete[] users;,但 delete 关键字本身也不会改变指针的值,所以根本想不到为什么代码中要判断 requestNULL....

看看有无大佬分析一下这里。

arglone commented 1 month ago

multi define issue, see #276