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


C++ ConnectionDescriptionPtr类代码示例

本文整理汇总了C++中ConnectionDescriptionPtr的典型用法代码示例。如果您正苦于以下问题:C++ ConnectionDescriptionPtr类的具体用法?C++ ConnectionDescriptionPtr怎么用?C++ ConnectionDescriptionPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: UUID

bool PipeConnection::_createPipes()
{
    std::stringstream pipeName;
    pipeName << "\\\\.\\pipe\\Collage." << UUID( true );

    ConnectionDescriptionPtr desc = new ConnectionDescription;
    desc->type = CONNECTIONTYPE_NAMEDPIPE;
    desc->setFilename( pipeName.str( ));

    ConnectionPtr connection = Connection::create( desc );
    _namedPipe = static_cast< NamedPipeConnection* >( connection.get( ));
    if( !_namedPipe->listen( ))
        return false;
    _namedPipe->acceptNB();

    connection = Connection::create( desc );
    _sibling->_namedPipe = static_cast<NamedPipeConnection*>(connection.get());
    if( !_sibling->_namedPipe->connect( ))
    {
        _sibling->_namedPipe = 0;
        return false;
    }

    connection = _namedPipe->acceptSync();
    _namedPipe = static_cast< NamedPipeConnection* >(connection.get( ));
    return true;
}
开发者ID:bohara,项目名称:Collage,代码行数:27,代码来源:pipeConnection.cpp

示例2: LB_TS_THREAD

ConnectionPtr SocketConnection::acceptSync()
{
    LB_TS_THREAD( _recvThread );
    if( !isListening( ))
        return 0;

    LBASSERT( _overlappedAcceptData );
    LBASSERT( _overlappedSocket != INVALID_SOCKET );
    if( _overlappedSocket == INVALID_SOCKET )
        return 0;

    // complete accept
    DWORD got   = 0;
    DWORD flags = 0;

    if( !WSAGetOverlappedResult( _readFD, &_overlappedRead, &got, TRUE,
                                 &flags ))
    {
        LBWARN << "Accept completion failed: " << lunchbox::sysError
               << ", closing socket" << std::endl;
        close();
        return 0;
    }

    sockaddr_in* local     = 0;
    sockaddr_in* remote    = 0;
    int          localLen  = 0;
    int          remoteLen = 0;
    GetAcceptExSockaddrs( _overlappedAcceptData, 0, sizeof( sockaddr_in ) + 16,
                          sizeof( sockaddr_in ) + 16, (sockaddr**)&local,
                          &localLen, (sockaddr**)&remote, &remoteLen );
    _tuneSocket( _overlappedSocket );

    ConstConnectionDescriptionPtr description = getDescription();
    SocketConnection* newConnection = new SocketConnection;
    ConnectionPtr connection( newConnection ); // to keep ref-counting correct

    newConnection->_readFD  = _overlappedSocket;
    newConnection->_writeFD = _overlappedSocket;

#ifndef _WIN32
    //fcntl( _overlappedSocket, F_SETFL, O_NONBLOCK );
#endif

    newConnection->_initAIORead();
    _overlappedSocket       = INVALID_SOCKET;

    newConnection->_setState( STATE_CONNECTED );
    ConnectionDescriptionPtr newDescription = newConnection->_getDescription();
    newDescription->bandwidth = description->bandwidth;
    newDescription->port = ntohs( remote->sin_port );
    newDescription->setHostname( getHostName( *remote ));

    LBDEBUG << "accepted connection from " << newDescription->getHostname()
           << ":" << newDescription->port << std::endl;
    return connection;
}
开发者ID:tribal-tec,项目名称:Collage,代码行数:57,代码来源:socketConnection.cpp

示例3: EQASSERT

void LocalNode::_connectMulticast( NodePtr node )
{
    EQASSERT( _inReceiverThread( ));
    base::ScopedMutex<> mutex( _outMulticast );

    if( node->_outMulticast.data.isValid( ))
        // multicast already connected by previous _cmdID
        return;

    // Search if the connected node is in the same multicast group as we are
    ConnectionDescriptions descriptions = getConnectionDescriptions();
    for( ConnectionDescriptions::const_iterator i = descriptions.begin();
         i != descriptions.end(); ++i )
    {
        ConnectionDescriptionPtr description = *i;
        if( description->type < CONNECTIONTYPE_MULTICAST )
            continue;

        const ConnectionDescriptions& fromDescs =
            node->getConnectionDescriptions();
        for( ConnectionDescriptions::const_iterator j = fromDescs.begin();
             j != fromDescs.end(); ++j )
        {
            ConnectionDescriptionPtr fromDescription = *j;
            if( !description->isSameMulticastGroup( fromDescription ))
                continue;
            
            EQASSERT( !node->_outMulticast.data );
            EQASSERT( node->_multicasts.empty( ));

            if( _outMulticast->isValid() && 
                _outMulticast.data->getDescription() == description )
            {
                node->_outMulticast.data = _outMulticast.data;
                EQINFO << "Using " << description << " as multicast group for "
                       << node->getNodeID() << std::endl;
            }
            // find unused multicast connection to node
            else for( MCDatas::const_iterator k = _multicasts.begin();
                      k != _multicasts.end(); ++k )
            {
                const MCData& data = *k;
                ConnectionDescriptionPtr dataDesc = 
                    data.connection->getDescription();
                if( !description->isSameMulticastGroup( dataDesc ))
                    continue;

                node->_multicasts.push_back( data );
                EQINFO << "Adding " << dataDesc << " as multicast group for "
                       << node->getNodeID() << std::endl;
            }
        }
    }
}
开发者ID:MichaelVlad,项目名称:Equalizer,代码行数:54,代码来源:localNode.cpp

示例4: serialize

std::string serialize( const ConnectionDescriptions& descriptions )
{
    std::ostringstream data;
    data << descriptions.size() << CO_SEPARATOR;

    for( ConnectionDescriptions::const_iterator i = descriptions.begin();
         i != descriptions.end(); ++i )
    {
        ConnectionDescriptionPtr desc = *i;
        desc->serialize( data );
    }

    return data.str();
}
开发者ID:4Second2None,项目名称:Collage,代码行数:14,代码来源:connectionDescription.cpp

示例5: UDTLASTERROR

// caller: application
ConnectionPtr UDTConnection::acceptSync( )
{
    struct sockaddr address;
    int addrlen;

    UDTSOCKET newSocket = UDT::accept( _udt, &address, &addrlen );
    UDTConnectionPtr newConnection = new UDTConnection;

    if( UDT::INVALID_SOCK == newSocket )
    {
        LBERROR << UDTLASTERROR( "UDT::accept" ) << std::endl;
        close( );
        goto err;
    }

    acknowledge( _notifier );

    newConnection->_udt = newSocket;

    // Do this after accept, otherwise accept itself becomes non-blocking
    static const bool OFF = false;
    if( newConnection->setSockOpt( UDT_RCVSYN,
                                   static_cast<const void *>( &OFF ),
                                   sizeof(OFF) ))
    {
        ConnectionDescriptionPtr desc = newConnection->_getDescription();
        desc->setHostname( ::inet_ntoa(
                                  ((struct sockaddr_in *)&address)->sin_addr ));
        desc->port = ntohs( ((struct sockaddr_in *)&address)->sin_port );
        desc->bandwidth = getDescription()->bandwidth;
        if( newConnection->initialize( ))
        {
            newConnection->_setState( STATE_CONNECTED );
            goto out;
        }
    }
    // else goto err;
err:
    newConnection = 0;

out:
    // Let the event thread continue polling
    lunchbox::ScopedMutex<> mutex( _app_mutex );

    _app_block.set( true );

    return newConnection;
}
开发者ID:4Second2None,项目名称:Collage,代码行数:49,代码来源:udtConnection.cpp

示例6: _setDescription

void Connection::_setDescription( ConnectionDescriptionPtr description )
{
    LBASSERT( description.isValid( ));
    LBASSERTINFO( _impl->description->type == description->type,
                  "Wrong connection type in description" );
    _impl->description = description;
    LBASSERT( description->bandwidth > 0 );
}
开发者ID:tribal-tec,项目名称:Collage,代码行数:8,代码来源:connection.cpp

示例7: setDescription

void Connection::setDescription( ConnectionDescriptionPtr description )
{
    EQASSERT( description.isValid( ));
    EQASSERTINFO( _description->type == description->type,
                  "Wrong connection type in description" );
    _description = description;
    EQASSERT( description->bandwidth > 0 );
}
开发者ID:cstalder,项目名称:Equalizer,代码行数:8,代码来源:connection.cpp

示例8: typeid

std::ostream& operator << ( std::ostream& os, const Connection& connection )
{
    Connection::State        state = connection.getState();
    ConnectionDescriptionPtr desc  = connection.getDescription();

    os << "Connection " << (void*)&connection << " type "
       << typeid( connection ).name() << " state "
       << ( state == Connection::STATE_CLOSED     ? "closed" :
            state == Connection::STATE_CONNECTING ? "connecting" :
            state == Connection::STATE_CONNECTED  ? "connected" :
            state == Connection::STATE_LISTENING  ? "listening" :
            state == Connection::STATE_CLOSING    ? "closing" :
            "UNKNOWN" );
    if( desc.isValid( ))
        os << " description " << desc->toString();

    return os;
}
开发者ID:cstalder,项目名称:Equalizer,代码行数:18,代码来源:connection.cpp

示例9: deserialize

bool deserialize( std::string& data, ConnectionDescriptions& descriptions )
{
    if( !descriptions.empty( ))
        LBWARN << "Connection descriptions already hold data before deserialize"
               << std::endl;

    // num connection descriptions
    size_t nextPos = data.find( CO_SEPARATOR );
    if( nextPos == std::string::npos || nextPos == 0 )
    {
        LBERROR << "Could not parse number of connection descriptions"
                << std::endl;
        return false;
    }

    const std::string sizeStr = data.substr( 0, nextPos );
    if( !isdigit( sizeStr[0] ))
    {
        LBERROR << "Could not parse number of connection descriptions"
                << std::endl;
        return false;
    }

    const size_t nDesc = atoi( sizeStr.c_str( ));
    data = data.substr( nextPos + 1 );

    // connection descriptions
    for( size_t i = 0; i < nDesc; ++i )
    {
        ConnectionDescriptionPtr desc = new ConnectionDescription;
        if( !desc->fromString( data ))
        {
            LBERROR << "Error during connection description parsing"
                    << std::endl;
            return false;
        }
        descriptions.push_back( desc );
    }

    return true;
}
开发者ID:4Second2None,项目名称:Collage,代码行数:41,代码来源:connectionDescription.cpp

示例10: sizeof

ConnectionPtr SocketConnection::acceptSync()
{
    if( !isListening( ))
        return 0;

    sockaddr_in newAddress;
    socklen_t   newAddressLen = sizeof( newAddress );

    Socket    fd;
    unsigned  nTries = 1000;
    do
        fd = ::accept( _readFD, (sockaddr*)&newAddress, &newAddressLen );
    while( fd == INVALID_SOCKET && errno == EINTR && --nTries );

    if( fd == INVALID_SOCKET )
    {
      LBWARN << "accept failed: " << lunchbox::sysError << std::endl;
        return 0;
    }

    _tuneSocket( fd );

    ConstConnectionDescriptionPtr description = getDescription();
    SocketConnection* newConnection = new SocketConnection;

    newConnection->_readFD      = fd;
    newConnection->_writeFD     = fd;
    newConnection->_setState( STATE_CONNECTED );
    ConnectionDescriptionPtr newDescription = newConnection->_getDescription();
    newDescription->bandwidth = description->bandwidth;
    newDescription->port = ntohs( newAddress.sin_port );
    newDescription->setHostname( inet_ntoa( newAddress.sin_addr ));

    LBDEBUG << "Accepted " << newDescription->toString() << std::endl;
    return newConnection;
}
开发者ID:tribal-tec,项目名称:Collage,代码行数:36,代码来源:socketConnection.cpp

示例11: _getDescription

//----------------------------------------------------------------------
// listen
//----------------------------------------------------------------------
bool SocketConnection::listen()
{
    ConnectionDescriptionPtr description = _getDescription();
    LBASSERT( description->type == CONNECTIONTYPE_TCPIP );

    if( !isClosed( ))
        return false;

    _setState( STATE_CONNECTING );

    sockaddr_in address;
    const size_t size = sizeof( sockaddr_in );

    if( !_parseAddress( description, address ))
    {
        LBWARN << "Can't parse connection parameters" << std::endl;
        return false;
    }

    if( !_createSocket())
        return false;

    const bool bound = (::bind( _readFD, (sockaddr *)&address, size ) == 0);

    if( !bound )
    {
        LBWARN << "Could not bind socket " << _readFD << ": "
               << lunchbox::sysError << " to " << getHostName( address )
               << ":" << ntohs( address.sin_port ) << " AF "
               << (int)address.sin_family << std::endl;

        close();
        return false;
    }

    if( ::listen( _readFD, SOMAXCONN ) != 0 )
    {
        LBWARN << "Could not listen on socket: " << lunchbox::sysError
               << std::endl;
        close();
        return false;
    }

    // get socket parameters
    socklen_t used = size;
    getsockname( _readFD, (struct sockaddr *)&address, &used );
    description->port = ntohs( address.sin_port );

    std::string hostname = description->getHostname();
    if( hostname.empty( ))
    {
        if( address.sin_addr.s_addr == INADDR_ANY )
        {
            char cHostname[256] = {0};
            gethostname( cHostname, 256 );
            hostname = cHostname;

            description->setHostname( hostname );
        }
        else
            description->setHostname( getHostName( address ));
    }

    _initAIOAccept();
    _setState( STATE_LISTENING );

    LBDEBUG << "Listening on " << description->getHostname() << "["
           << getHostName( address ) << "]:" << description->port
           << " (" << description->toString() << ")" << std::endl;

    return true;
}
开发者ID:tribal-tec,项目名称:Collage,代码行数:75,代码来源:socketConnection.cpp


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