/** * dispatch data to worker */ int swProcessPool_dispatch(swProcessPool *pool, swEventData *data, int *dst_worker_id) { int ret = 0; swWorker *worker; if (*dst_worker_id < 0) { *dst_worker_id = swProcessPool_schedule(pool); } *dst_worker_id += pool->start_id; worker = swProcessPool_get_worker(pool, *dst_worker_id); int sendn = sizeof(data->info) + data->info.len; ret = swWorker_send2worker(worker, data, sendn, SW_PIPE_MASTER | SW_PIPE_NONBLOCK); if (ret >= 0) { sw_atomic_fetch_add(&worker->tasking_num, 1); } else { swWarn("send %d bytes to worker#%d failed.", sendn, *dst_worker_id); } return ret; }
void swTaskWorker_onStart(swProcessPool *pool, int worker_id) { swServer *serv = pool->ptr; SwooleWG.id = worker_id; SwooleG.use_timer_pipe = 0; SwooleG.use_timerfd = 0; swTaskWorker_signal_init(); swWorker_onStart(serv); SwooleWG.worker = swProcessPool_get_worker(pool, worker_id); }
void swTaskWorker_onStart(swProcessPool *pool, int worker_id) { swServer *serv = pool->ptr; SwooleWG.id = worker_id; SwooleG.use_timer_pipe = 0; SwooleG.use_timerfd = 0; swTaskWorker_signal_init(); swWorker_onStart(serv); SwooleG.main_reactor = NULL; SwooleWG.worker = swProcessPool_get_worker(pool, worker_id); SwooleWG.worker->status = SW_WORKER_IDLE; }
/** * dispatch data to worker */ int swProcessPool_dispatch_blocking(swProcessPool *pool, swEventData *data, int *dst_worker_id) { int ret = 0; int sendn = sizeof(data->info) + data->info.len; if (pool->use_socket) { swClient _socket; if (swClient_create(&_socket, SW_SOCK_UNIX_STREAM, SW_SOCK_SYNC) < 0) { return SW_ERR; } if (_socket.connect(&_socket, pool->stream->socket_file, 0, -1, 0) < 0) { return SW_ERR; } if (_socket.send(&_socket, (void*) data, sendn, 0) < 0) { return SW_ERR; } _socket.close(&_socket); return SW_OK; } if (*dst_worker_id < 0) { *dst_worker_id = swProcessPool_schedule(pool); } *dst_worker_id += pool->start_id; swWorker *worker = swProcessPool_get_worker(pool, *dst_worker_id); ret = swWorker_send2worker(worker, data, sendn, SW_PIPE_MASTER); if (ret < 0) { swWarn("send %d bytes to worker#%d failed.", sendn, *dst_worker_id); } else { sw_atomic_fetch_add(&worker->tasking_num, 1); } return ret; }
/** * dispatch data to worker */ int swProcessPool_dispatch(swProcessPool *pool, swEventData *data, int *dst_worker_id) { int ret = 0; swWorker *worker; if (pool->use_socket) { swStream *stream = swStream_new(pool->stream->socket_file, 0, SW_SOCK_UNIX_STREAM); if (stream == NULL) { return SW_ERR; } stream->response = NULL; stream->session_id = 0; if (swStream_send(stream, (char*) data, sizeof(data->info) + data->info.len) < 0) { stream->cancel = 1; return SW_ERR; } return SW_OK; } if (*dst_worker_id < 0) { *dst_worker_id = swProcessPool_schedule(pool); } *dst_worker_id += pool->start_id; worker = swProcessPool_get_worker(pool, *dst_worker_id); int sendn = sizeof(data->info) + data->info.len; ret = swWorker_send2worker(worker, data, sendn, SW_PIPE_MASTER | SW_PIPE_NONBLOCK); if (ret >= 0) { sw_atomic_fetch_add(&worker->tasking_num, 1); } else { swWarn("send %d bytes to worker#%d failed.", sendn, *dst_worker_id); } return ret; }
void swTaskWorker_onStart(swProcessPool *pool, int worker_id) { swServer *serv = pool->ptr; SwooleWG.id = worker_id; SwooleG.pid = getpid(); SwooleG.use_timer_pipe = 0; SwooleG.use_timerfd = 0; swServer_close_port(serv, SW_TRUE); swTaskWorker_signal_init(); swWorker_onStart(serv); SwooleG.main_reactor = NULL; swWorker *worker = swProcessPool_get_worker(pool, worker_id); worker->start_time = serv->gs->now; worker->request_count = 0; worker->traced = 0; SwooleWG.worker = worker; SwooleWG.worker->status = SW_WORKER_IDLE; }
/** * dispatch data to worker */ int swProcessPool_dispatch_blocking(swProcessPool *pool, swEventData *data, int *dst_worker_id) { int ret = 0; swWorker *worker; if (*dst_worker_id < 0) { *dst_worker_id = swProcessPool_schedule(pool); } *dst_worker_id += pool->start_id; worker = swProcessPool_get_worker(pool, *dst_worker_id); int sendn = sizeof(data->info) + data->info.len; ret = swWorker_send2worker(worker, data, sendn, SW_PIPE_MASTER); if (ret < 0) { swWarn("send %d bytes to worker#%d failed.", sendn, *dst_worker_id); } return ret; }