本文整理汇总了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;
}
}
示例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;
}
}