muduo测试部分的代码
This commit is contained in:
parent
1e49c92b6c
commit
4a602b5213
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"functional": "cpp"
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user