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


C++ Host::unpack方法代码示例

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


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

示例1: getHosts

void HostTab::getHosts( void ) {

    hosts.clear();

    if( !connection || !*connection ) {
        return;
    }

    uint8_t cmd = CMD_PSTAT;
    boost::asio::write(connection->socket(),boost::asio::buffer(&cmd,1));

    size_t blockSize;
    uint64_t count(0);
    shared_ptr<char> buf = connection->receiveBlock( blockSize );
    
    if( !blockSize ) return;

    const char* ptr = buf.get();
    try {
        Host host;
        while( count < blockSize ) {
            count += host.unpack( ptr+count, swap_endian );
            hosts.insert( Host::Ptr(new Host(host.info)) );
        }
    }
    catch( const exception& e ) {
        cout << "getPeers: Exception caught while parsing block: " << e.what() << endl;
    }
    
    if( count != blockSize ) {
        cout << "getPeers: Parsing of datablock failed,  count = " << count << "  blockSize = " << blockSize << " bytes." << endl;
    }


}
开发者ID:ISP-SST,项目名称:redux,代码行数:35,代码来源:hosttab.cpp

示例2: printPeerList

void printPeerList( TcpConnection::Ptr conn, int ns ) {

    uint8_t cmd = CMD_PSTAT;
    boost::asio::write(conn->socket(),boost::asio::buffer(&cmd,1));

    uint64_t blockSize;
    shared_ptr<char> buf = conn->receiveBlock( blockSize );

    if ( !blockSize ) return;

    const char* ptr = buf.get();
    uint64_t count(0);
    try {
        Host peer;
        cout << "    " << peer.printHeader() << endl;
        int hostCount(0);
        while( count < blockSize ) {
            count += peer.unpack(ptr+count,conn->getSwapEndian());
            if ( hostCount == 0 ) cout << "    " << peer.print() << endl;
            else if ( ns==0 || hostCount < ns) cout << alignRight(to_string(hostCount),4) << peer.print() << endl;
            hostCount++;
        }
        if (ns!=0 && hostCount > ns) cout << "   :" << endl << alignRight(to_string(hostCount),4) << peer.print() << endl;
    } catch ( const exception& e) {
        cerr << "printPeerList: Exception caught while parsing block: " << e.what() << endl;
    }
    if( count != blockSize ) {
        cerr << "printPeerList: Parsing of datablock failed, count = " << count << "  blockSize = " << blockSize << "  bytes." << endl;
    }
}
开发者ID:ISP-SST,项目名称:redux,代码行数:30,代码来源:rstat.cpp


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