muduo测试部分的代码

This commit is contained in:
cuicui 2024-12-26 16:50:27 +08:00
parent 1e49c92b6c
commit 4a602b5213
2 changed files with 25 additions and 2 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.associations": {
"functional": "cpp"
}
}

View File

@ -18,6 +18,15 @@ using namespace muduo;
using namespace muduo::net; using namespace muduo::net;
using namespace placeholders; using namespace placeholders;
/*
muduo网络库开发服务器程序
1.TcpServer对象
2.
3.TcpServer构造函数需要什么参数ChatServer的构造函数
4.
5.线,muduo库会自己分配I/O线程和worker线程
*/
class ChatServer{ class ChatServer{
public: public:
ChatServer(EventLoop* loop, ChatServer(EventLoop* loop,
@ -27,17 +36,26 @@ public:
{ {
//给服务器注册用户连接的创建和断开回调 //给服务器注册用户连接的创建和断开回调
_server.setConnectionCallback(std::bind(&ChatServer::onConnection, this, _1)); _server.setConnectionCallback(std::bind(&ChatServer::onConnection, this, _1));
//给服务器注册用户读写事件的回调 //给服务器注册用户读写事件的回调
//_server.setMessageCallback(); _server.setMessageCallback(std::bind(&ChatServer::onMessage, this, _1, _2, _3));
//设置服务器端的线程数量 1个I/O线程 3个worker线程
_server.setThreadNum(4);
} }
void start(){
_server.start();
}
private: private:
void onConnection(const TcpConnectionPtr&) void onConnection(const TcpConnectionPtr&)
{ {
} }
void Message(const MessageCallback& cb) void onMessage(const TcpConnectionPtr& conn,
Buffer* buffer,
Timestamp time)
{ {
} }