/** * 使用消息队列通信 */ int swFactoryProcess_writer_loop_queue(swThreadParam *param) { swFactory *factory = param->object; swFactoryProcess *object = factory->object; int pti = param->pti; swQueue_data sdata; //必须加1,msg_type必须不能为0 sdata.mtype = pti + 1; swSingalNone(); while (SwooleG.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 { swReactorThread_response((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); //swWarn("send: type=%d|content=%s", resp.info.type, resp.data); if (n > 0) { return swReactorThread_response(&resp); } else { swWarn("[WriteThread]sento fail. Error: %s[%d]", strerror(errno), errno); return SW_ERR; } }