11#include "muduo/protobuf/dispatcher.h"
12#include "muduo/protobuf/codec.h"
14#include "muduo/base/Mutex.h"
15#include "muduo/base/Logging.h"
16#include "muduo/net/EventLoop.h"
17#include "muduo/net/TcpClient.h"
18#include "muduo/net/EventLoopThread.h"
19#include "muduo/base/CountDownLatch.h"
22#include "../common/logger.hpp"
31 using ptr = std::shared_ptr<Connection>;
37 :
_latch(1),
_client(worker->_loopthread.startLoop(), muduo::net::InetAddress(sip, sport),
"Client"),
39 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)),
40 _codec(std::make_shared<ProtobufCodec>(std::bind(&ProtobufDispatcher::onProtobufMessage, &
_dispatcher,
41 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))),
45 std::placeholders::_2, std::placeholders::_3));
47 std::placeholders::_2, std::placeholders::_3));
48 _client.setMessageCallback(std::bind(&ProtobufCodec::onMessage,
_codec, std::placeholders::_1,
49 std::placeholders::_2, std::placeholders::_3));
59 bool ret = channel->openChannel();
71 channel->closeChannel();
84 if (channel ==
nullptr)
90 channel->putBasicResponse(message);
100 if (channel ==
nullptr)
106 _worker->_threadpool.push([channel, message]()
107 { channel->consume(message); });
113 if (conn->connected())
129 info(
logger,
"onUnknowMessage: %s", message->GetTypeName());
std::shared_ptr< AsyncWorker > ptr
异步工作线程管理句柄
Definition worker.hpp:17
std::shared_ptr< Channel > ptr
信道句柄
Definition channel.hpp:32
信道管理类
Definition channel.hpp:317
std::shared_ptr< ChannelManager > ptr
信道管理句柄
Definition channel.hpp:319
连接管理模块
Definition connection.hpp:29
ProtobufCodecPtr _codec
协议处理器
Definition connection.hpp:138
Channel::ptr openChannel()
创建信道
Definition connection.hpp:56
ProtobufDispatcher _dispatcher
请求分发器
Definition connection.hpp:137
void closeChannel(const Channel::ptr &channel)
关闭信道
Definition connection.hpp:69
Connection(const std::string &sip, int sport, const AsyncWorker::ptr &worker)
连接构造函数
Definition connection.hpp:36
std::shared_ptr< Connection > ptr
连接管理句柄
Definition connection.hpp:31
muduo::CountDownLatch _latch
实现同步
Definition connection.hpp:134
void onConnection(const muduo::net::TcpConnectionPtr &conn)
连接回调函数
Definition connection.hpp:111
muduo::net::TcpClient _client
客户端句柄
Definition connection.hpp:136
ChannelManager::ptr _channels
信道管理句柄
Definition connection.hpp:140
AsyncWorker::ptr _worker
异步线程工作器
Definition connection.hpp:139
void commonResponse(const muduo::net::TcpConnectionPtr &conn, const basicResponsePtr message, muduo::Timestamp)
处理一般响应的回调函数
Definition connection.hpp:80
muduo::net::TcpConnectionPtr _conn
客户端连接
Definition connection.hpp:135
void onUnknowMessage(const muduo::net::TcpConnectionPtr &conn, const MessagePtr &message, muduo::Timestamp)
未知响应回调函数
Definition connection.hpp:127
void consumeResponse(const muduo::net::TcpConnectionPtr &conn, const basicConsumeResponsePtr message, muduo::Timestamp)
处理消费响应的回调函数
Definition connection.hpp:96
Definition protocol.pb.h:2629
Definition protocol.pb.h:2834
Definition channel.hpp:22
Xulog::Logger::ptr logger
日志器的智能指针类型
Definition logger.hpp:24
std::shared_ptr< google::protobuf::Message > MessagePtr
消息句柄
Definition channel.hpp:23
std::shared_ptr< basicResponse > basicResponsePtr
其他响应句柄
Definition channel.hpp:26
std::shared_ptr< basicConsumeResponse > basicConsumeResponsePtr
消费响应句柄
Definition channel.hpp:25
std::shared_ptr< ProtobufCodec > ProtobufCodecPtr
协议处理句柄
Definition channel.hpp:24
信道与信道管理模块的头文件,包含了信道的声明和其管理类的定义。