/** * 使用消息队列通信 */ int swFactoryProcess_writer_loop_queue(swThreadParam *param) { swFactory *factory = param->object; swFactoryProcess *object = factory->object; swServer *serv = factory->ptr; int ret; int pti = param->pti; swQueue_data sdata; //必须加1,msg_type必须不能为0 sdata.mtype = pti + 1; swSingalNone(); while (swoole_running > 0) { swTrace("[Writer]wt_queue[%ld]->out wait", sdata.mtype); int ret = object->wt_queue.out(&object->wt_queue, &sdata, sizeof(sdata.mdata)); if (ret < 0) { swWarn("[writer]wt_queue->out fail.Error: %s [%d]", strerror(errno), errno); } else { swFactoryProcess_writer_excute(factory, (swEventData *)sdata.mdata); } } pthread_exit((void *) param); return SW_OK; }
int swFactoryProcess_send2client(swReactor *reactor, swDataHead *ev) { int n; swEventData resp; //Unix Sock UDP n = read(ev->fd, &resp, sizeof(resp)); swTrace("[WriteThread]recv: writer=%d|pipe=%d", ev->from_id, ev->fd); if (n > 0) { return swFactoryProcess_writer_excute(&resp); } else { swWarn("[WriteThread]sento fail. Error: %s[%d]", strerror(errno), errno); return SW_ERR; } }
int swFactoryProcess_writer_receive(swReactor *reactor, swDataHead *ev) { int n, ret; swFactory *factory = reactor->factory; swServer *serv = factory->ptr; swEventData resp; //Unix Sock UDP n = read(ev->fd, &resp, sizeof(resp)); swTrace("[WriteThread]recv: writer=%d|pipe=%d\n", ev->from_id, ev->fd); if (n > 0) { return swFactoryProcess_writer_excute(factory, &resp); } else { swWarn("[WriteThread]sento fail.errno=%d\n", errno); return SW_ERR; } }