@@ -32,11 +32,6 @@ namespace swoole {
32
32
using network::Socket;
33
33
using network::Stream;
34
34
35
- static int ProcessPool_worker_loop_with_task_protocol (ProcessPool *pool, Worker *worker);
36
- static int ProcessPool_worker_loop_with_stream_protocol (ProcessPool *pool, Worker *worker);
37
- static int ProcessPool_worker_loop_with_message_protocol (ProcessPool *pool, Worker *worker);
38
- static int ProcessPool_worker_loop_async (ProcessPool *pool, Worker *worker);
39
-
40
35
void ProcessPool::kill_timeout_worker (Timer *timer, TimerNode *tnode) {
41
36
uint32_t i;
42
37
pid_t reload_worker_pid = 0 ;
@@ -113,7 +108,7 @@ int ProcessPool::create(uint32_t _worker_num, key_t _msgqueue_key, swIPCMode _ip
113
108
114
109
map_ = new std::unordered_map<pid_t , Worker *>;
115
110
ipc_mode = _ipc_mode;
116
- main_loop = ProcessPool_worker_loop_with_task_protocol ;
111
+ main_loop = run_with_task_protocol ;
117
112
protocol_type_ = SW_PROTOCOL_TASK;
118
113
max_packet_size_ = SW_INPUT_BUFFER_SIZE;
119
114
@@ -207,13 +202,13 @@ int ProcessPool::listen(const char *host, int port, int blacklog) {
207
202
void ProcessPool::set_protocol (enum ProtocolType _protocol_type) {
208
203
switch (_protocol_type) {
209
204
case SW_PROTOCOL_TASK:
210
- main_loop = ProcessPool_worker_loop_with_task_protocol ;
205
+ main_loop = run_with_task_protocol ;
211
206
break ;
212
207
case SW_PROTOCOL_STREAM:
213
- main_loop = ProcessPool_worker_loop_with_stream_protocol ;
208
+ main_loop = run_with_stream_protocol ;
214
209
break ;
215
210
case SW_PROTOCOL_MESSAGE:
216
- main_loop = ProcessPool_worker_loop_with_message_protocol ;
211
+ main_loop = run_with_message_protocol ;
217
212
break ;
218
213
default :
219
214
abort ();
@@ -234,7 +229,7 @@ int ProcessPool::start_check() {
234
229
swoole_set_process_type (SW_PROCESS_MASTER);
235
230
236
231
if (async) {
237
- main_loop = ProcessPool_worker_loop_async ;
232
+ main_loop = run_async ;
238
233
}
239
234
240
235
SW_LOOP_N (worker_num) {
@@ -507,7 +502,7 @@ bool ProcessPool::is_worker_running(Worker *worker) {
507
502
return running && !SwooleWG.shutdown && !worker->has_exceeded_max_request ();
508
503
}
509
504
510
- static int ProcessPool_worker_loop_with_task_protocol (ProcessPool *pool, Worker *worker) {
505
+ int ProcessPool::run_with_task_protocol (ProcessPool *pool, Worker *worker) {
511
506
struct {
512
507
long mtype;
513
508
EventData buf;
@@ -626,7 +621,7 @@ static int ProcessPool_recv_message(Reactor *reactor, Event *event) {
626
621
return SW_OK;
627
622
}
628
623
629
- static int ProcessPool_worker_loop_async (ProcessPool *pool, Worker *worker) {
624
+ int ProcessPool::run_async (ProcessPool *pool, Worker *worker) {
630
625
if (pool->ipc_mode == SW_IPC_UNIXSOCK && pool->onMessage ) {
631
626
swoole_event_add (worker->pipe_worker , SW_EVENT_READ);
632
627
if (pool->message_bus ) {
@@ -642,7 +637,7 @@ static int ProcessPool_worker_loop_async(ProcessPool *pool, Worker *worker) {
642
637
return swoole_event_wait ();
643
638
}
644
639
645
- static int ProcessPool_worker_loop_with_stream_protocol (ProcessPool *pool, Worker *worker) {
640
+ int ProcessPool::run_with_stream_protocol (ProcessPool *pool, Worker *worker) {
646
641
ssize_t n;
647
642
RecvData msg{};
648
643
msg.info .reactor_id = -1 ;
@@ -652,6 +647,10 @@ static int ProcessPool_worker_loop_with_stream_protocol(ProcessPool *pool, Worke
652
647
pool->stream_info_ ->response_buffer = new String (SW_BUFFER_SIZE_STD);
653
648
}
654
649
650
+ if (pool->ipc_mode == SW_IPC_UNIXSOCK && pool->message_bus == nullptr ) {
651
+ pool->create_message_bus ();
652
+ }
653
+
655
654
QueueNode *outbuf = (QueueNode *) pool->packet_buffer ;
656
655
outbuf->mtype = 0 ;
657
656
@@ -739,7 +738,7 @@ static int ProcessPool_worker_loop_with_stream_protocol(ProcessPool *pool, Worke
739
738
return SW_OK;
740
739
}
741
740
742
- static int ProcessPool_worker_loop_with_message_protocol (ProcessPool *pool, Worker *worker) {
741
+ int ProcessPool::run_with_message_protocol (ProcessPool *pool, Worker *worker) {
743
742
auto fn = [&]() -> int {
744
743
if (worker->pipe_worker ->wait_event (-1 , SW_EVENT_READ) < 0 ) {
745
744
return errno == EINTR ? 0 : -1 ;
@@ -758,6 +757,16 @@ static int ProcessPool_worker_loop_with_message_protocol(ProcessPool *pool, Work
758
757
return 1 ;
759
758
};
760
759
760
+ if (pool->ipc_mode != SW_IPC_UNIXSOCK) {
761
+ swoole_error_log (
762
+ SW_LOG_WARNING, SW_ERROR_OPERATION_NOT_SUPPORT, " not support, ipc_mode must be SW_IPC_UNIXSOCK" );
763
+ return SW_ERR;
764
+ }
765
+
766
+ if (pool->message_bus == nullptr ) {
767
+ pool->create_message_bus ();
768
+ }
769
+
761
770
worker->pipe_worker ->dont_restart = 1 ;
762
771
763
772
while (pool->is_worker_running (worker)) {
0 commit comments