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


C++ TcpSocket::Create方法代码示例

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


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

示例1: ReadData

    virtual int ReadData(int fd)
    {
        int err = 0;
        int clientFd = -1;
        std::string ip;
        int port = 0;

        do {
            err = mListenSocket->Accept(clientFd, ip, port);
            if (0 != err) {
                break;
            }

            TcpSocket *clientSocket = new TcpSocket();
            err = clientSocket->Create(clientFd);
            if (0 != err) {
                break;
            }
            
            debug_log("accpeter accept client " << ip << ":" << port);
            clientSocket->SetAddr(ip, port);

            AcceptContext *ctx = new AcceptContext(clientSocket);
            mNetService->Enqueue(ctx);
            OperContext::DecRef(ctx);

        } while(0);

        return 0;
    }
开发者ID:bymzy,项目名称:rpc,代码行数:30,代码来源:Accepter.hpp

示例2: Accept

    Socket::Status TcpListener::Accept(TcpSocket& socket)
    {
        if (GetHandle() == be::SocketBE::invalidSocket())
        {
            return Error;
        }

        sockaddr_in address;
        be::SocketBE::AddrLength length = sizeof(address);
        SocketHandle remote = ::accept(GetHandle(), reinterpret_cast<sockaddr*>(&address), &length);

        if (remote == be::SocketBE::invalidSocket())
            return be::SocketBE::getErrorStatus();

        socket.Close();
        socket.Create(remote);

        return Done;
    }
开发者ID:Dka8,项目名称:Client_Server,代码行数:19,代码来源:TcpListener.cpp

示例3: Accept

Socket::Status TcpListener::Accept(TcpSocket& socket)
{
    // Make sure that we're listening
    if (GetHandle() == priv::SocketImpl::InvalidSocket())
    {
        Err() << "Failed to accept a new connection, the socket is not listening" << std::endl;
        return Error;
    }

    // Accept a new connection
    sockaddr_in address;
    priv::SocketImpl::AddrLength length = sizeof(address);
    SocketHandle remote = accept(GetHandle(), reinterpret_cast<sockaddr*>(&address), &length);

    // Check for errors
    if (remote == priv::SocketImpl::InvalidSocket())
        return priv::SocketImpl::GetErrorStatus();

    // Initialize the new connected socket
    socket.Close();
    socket.Create(remote);

    return Done;
}
开发者ID:r9k,项目名称:EnigmaNet,代码行数:24,代码来源:TcpListener.cpp


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