2025-02-04 16:09:27 +08:00
|
|
|
#include "client_tcp_connect.hpp"
|
|
|
|
#include "abstract_tcp_connect.hpp"
|
|
|
|
#include "logger.hpp"
|
|
|
|
#include "tcp_client.hpp"
|
|
|
|
#include "tinypb_data.hpp"
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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<AbstractData> data(new TinypbData);
|
|
|
|
|
|
|
|
bool ret = m_client.getCoder().decoder(m_readBuffer, *data);
|
|
|
|
|
|
|
|
if(ret == false) {
|
|
|
|
logger() << "decode error";
|
|
|
|
break;
|
|
|
|
}
|
2025-02-05 20:50:31 +08:00
|
|
|
|
2025-02-04 16:09:27 +08:00
|
|
|
std::shared_ptr<TinypbData> tmp = std::dynamic_pointer_cast<TinypbData>(data);
|
|
|
|
m_respond_datas[tmp->msg_req] = data;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2025-02-05 20:50:31 +08:00
|
|
|
|
|
|
|
bool ClientTcpConnection::getResPackageData(const std::string& msg_req, std::shared_ptr<AbstractData>& 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;
|
|
|
|
}
|
2025-02-04 16:09:27 +08:00
|
|
|
}
|