当前位置: 首页>>代码示例>>C++>>正文


C++ HTTPServer::addWorkerClient方法代码示例

本文整理汇总了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);
    }
}
开发者ID:marinae,项目名称:http-server,代码行数:59,代码来源:callback.cpp



注:本文中的HTTPServer::addWorkerClient方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。