本文整理汇总了C++中ContextPtr::readCommand方法的典型用法代码示例。如果您正苦于以下问题:C++ ContextPtr::readCommand方法的具体用法?C++ ContextPtr::readCommand怎么用?C++ ContextPtr::readCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContextPtr
的用法示例。
在下文中一共展示了ContextPtr::readCommand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
bool P2pNode::fetchPeerList(ContextPtr connection) {
try {
COMMAND_HANDSHAKE::request request{ getNodeData(), getGenesisPayload() };
COMMAND_HANDSHAKE::response response;
OperationTimeout<P2pContext> timeout(m_dispatcher, *connection, m_cfg.getHandshakeTimeout());
connection->writeMessage(makeRequest(COMMAND_HANDSHAKE::ID, LevinProtocol::encode(request)));
LevinProtocol::Command cmd;
if (!connection->readCommand(cmd)) {
throw std::runtime_error("Connection closed unexpectedly");
}
if (!cmd.isResponse || cmd.command != COMMAND_HANDSHAKE::ID) {
throw std::runtime_error("Received unexpected reply");
}
if (!LevinProtocol::decode(cmd.buf, response)) {
throw std::runtime_error("Invalid reply format");
}
if (response.node_data.network_id != request.node_data.network_id) {
logger(ERROR) << *connection << "COMMAND_HANDSHAKE failed, wrong network: " << response.node_data.network_id;
return false;
}
return handleRemotePeerList(response.local_peerlist, response.node_data.local_time);
} catch (std::exception& e) {
logger(INFO) << *connection << "Failed to obtain peer list: " << e.what();
}
return false;
}