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


C++ io_service::notify_fork方法代码示例

本文整理汇总了C++中asio::io_service::notify_fork方法的典型用法代码示例。如果您正苦于以下问题:C++ io_service::notify_fork方法的具体用法?C++ io_service::notify_fork怎么用?C++ io_service::notify_fork使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在asio::io_service的用法示例。


在下文中一共展示了io_service::notify_fork方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fcntl

Wondruss::auth_slave::auth_slave(asio::io_service& io_service, Lobby* lobby)
    : service_slave(io_service, lobby)
{
    asio::local::stream_protocol::socket child_fdsock(io_service);
    asio::local::stream_protocol::socket child_rdsock(io_service);
    asio::local::stream_protocol::socket child_wrsock(io_service);
    asio::local::connect_pair(fdsock, child_fdsock);
    asio::local::connect_pair(rdsock, child_wrsock);
    asio::local::connect_pair(wrsock, child_rdsock);
    fcntl(fdsock.native(), F_SETFD, FD_CLOEXEC);
    fcntl(rdsock.native(), F_SETFD, FD_CLOEXEC);
    fcntl(wrsock.native(), F_SETFD, FD_CLOEXEC);
    io_service.notify_fork(asio::io_service::fork_prepare);
    pid_t newpid = fork();
    if (newpid == 0) {
        io_service.notify_fork(asio::io_service::fork_child);
        if(FD_SOCKETS != dup2(child_fdsock.native(), FD_SOCKETS)) {
            child_fdsock.send(asio::buffer("KO", 0));
            exit(0);
        }
        if(FD_LBY_TO_SLV != dup2(child_rdsock.native(), FD_LBY_TO_SLV)) {
            child_fdsock.send(asio::buffer("KO", 0));
            exit(0);
        }
        if(FD_SLV_TO_LBY != dup2(child_wrsock.native(), FD_SLV_TO_LBY)) {
            child_fdsock.send(asio::buffer("KO", 0));
            exit(0);
        }
        // TODO: find wondruss_auth a bit more sanely
        execl("./wondruss_auth", "wondruss_auth", nullptr);
        // if we get here, execl failed for some reason. Let's tell the lobby we failed.
        child_fdsock.send(asio::buffer("KO", 0));
        exit(0);
    }
    io_service.notify_fork(asio::io_service::fork_parent);
    char buf[3] = {0};
    fdsock.receive(asio::buffer(buf, 2)); //TODO: timeout
    if(strcmp(buf, "OK") != 0) {
        LOG_FATAL("Auth process gave us a bad startup msg. WTF?");
        // TODO: fail spectacularly
    } else {
        LOG_INFO("Auth startup OK! continuing...");
    }

    rdsock.async_receive(asio::null_buffers(), std::bind(std::mem_fn(&auth_slave::handle_slave_msg), this, std::placeholders::_1));
}
开发者ID:H-uru,项目名称:Wondruss,代码行数:46,代码来源:auth_slave.cpp


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