本文整理汇总了C++中HTTPServer::addWorkerClient方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServer::addWorkerClient方法的具体用法?C++ HTTPServer::addWorkerClient怎么用?C++ HTTPServer::addWorkerClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPServer
的用法示例。
在下文中一共展示了HTTPServer::addWorkerClient方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: worker_cb
void worker_cb(evutil_socket_t evs, short events, void *ptr) {
int client_fd;
ssize_t size;
int BUF_LEN = 32;
char buf[BUF_LEN];
struct msghdr msg;
struct iovec iov;
union {
struct cmsghdr cmsghdr;
char control[CMSG_SPACE(sizeof(int))];
} cmsgu;
struct cmsghdr *cmsg;
iov.iov_base = (void *)buf;
iov.iov_len = BUF_LEN;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = cmsgu.control;
msg.msg_controllen = sizeof(cmsgu.control);
size = recvmsg(evs, &msg, 0);
if (size < 0) {
perror("recvmsg");
exit(1);
}
cmsg = CMSG_FIRSTHDR(&msg);
if (cmsg && cmsg->cmsg_len == CMSG_LEN(sizeof(int))) {
if (cmsg->cmsg_level != SOL_SOCKET) {
fprintf(stderr, "invalid cmsg_level %d\n",
cmsg->cmsg_level);
exit(1);
}
if (cmsg->cmsg_type != SCM_RIGHTS) {
fprintf(stderr, "invalid cmsg_type %d\n",
cmsg->cmsg_type);
exit(1);
}
client_fd = *((int *)CMSG_DATA(cmsg));
printf("worker: received fd = %d\n", client_fd);
} else {
client_fd = -1;
}
if (client_fd != -1) {
/* Last parameter is http server object */
HTTPServer *srv = (HTTPServer *)ptr;
/* Add client to worker process */
srv->addWorkerClient(client_fd);
}
}