增加threading处理 threading_xx类 class threading_stream_server_t : public stream_server_t { private: struct thread_parameter_t { threading_stream_server_t* handler; socket_t* socket; address_t* address; thread_parameter_t(threading_stream_server_t* h, socket_t& s, address_t& a):handler(h), socket(new socket_t(s)), address(new address_t(a)){} ~thread_parameter_t(){handler=NULL;delete socket;socket=NULL;delete address;address=NULL;} }; public: threading_stream_server_t(const address_t& address, base_handler_t* handler, int family) :stream_server_t(address, handler, family) {} virtual ~threading_stream_server_t(){} static void* process_request_threadthread(void* thread_parameter); virtual int process_request(socket_t& client_socket, address_t& client_address); }; class threading_tcp_server_t : public threading_stream_server_t { public: threading_tcp_server_t(const address_t& address, base_handler_t* handler) :threading_stream_server_t(address, handler, AF_INET){} virtual ~threading_tcp_server_t(){} }; class threading_unix_stream_server_t : public threading_stream_server_t { public: threading_unix_stream_server_t(const address_t& address, base_handler_t* handler) :threading_stream_server_t(address, handler, AF_UNIX){} virtual ~threading_unix_stream_server_t(){} }; /* threading_stream_server_t */ void* threading_stream_server_t::process_request_threadthread(void* thread_parameter) { thread_parameter_t* p = (thread_parameter_t*)thread_parameter; threading_stream_server_t* handler = p->handler; socket_t& client_socket = *p->socket; address_t& client_address = *p->address; pthread_detach(pthread_self()); int ret = handler->finish_request(client_socket, client_address); if (ret) { handler->handle_error(client_socket, client_address); } handler->close_request(client_socket); delete p; pthread_exit(NULL); return NULL; } int threading_stream_server_t::process_request(socket_t& client_socket, address_t& client_address) { pthread_t pid = 0; thread_parameter_t* parameter = new thread_parameter_t(this, client_socket, client_address); int ret = pthread_create(&pid, NULL, process_request_threadthread, parameter); if (ret) { handle_error(client_socket, client_address); } return 0; }