#include "client_tcp_connect.hpp" #include "abstract_tcp_connect.hpp" #include "logger.hpp" #include "tcp_client.hpp" #include "tinypb_data.hpp" #include namespace tinyrpc { ClientTcpConnection::ClientTcpConnection(int fd, Reactor& reactor, TcpClient& cli) : AbstractTcpConnection(fd, reactor), m_client(cli) { } ClientTcpConnection::~ClientTcpConnection() { } void ClientTcpConnection::process() { while(m_readBuffer.getReadable() > 0) { std::shared_ptr data(new TinypbData); bool ret = m_client.getCoder().decoder(m_readBuffer, *data); if(ret == false) { logger() << "decode error"; break; } std::shared_ptr tmp = std::dynamic_pointer_cast(data); m_respond_datas[tmp->msg_req] = data; } } bool ClientTcpConnection::getResPackageData(const std::string& msg_req, std::shared_ptr& pb_struct) { auto it = m_respond_datas.find(msg_req); if(it == m_respond_datas.end()) return false; pb_struct = it->second; m_respond_datas.erase(it); return true; } }