Compare commits

..

8 Commits
cui ... main

Author SHA1 Message Date
4a602b5213 muduo测试部分的代码 2024-12-26 16:50:27 +08:00
1e49c92b6c muduo测试框架回调函数 2024-12-25 20:01:55 +08:00
b6f13379ad Merge branch 'cui' 2024-12-23 20:56:44 +08:00
3c25f57851 muduo测试的框架 2024-12-23 20:55:55 +08:00
dbde770e4f Merge branch 'main' of http://git.shiftingnow.me/yhy1uj/ChatServer into main 2024-12-07 20:37:35 +08:00
4cc145203a add cout 100 2024-12-07 20:32:47 +08:00
9e17207e03 更新 main.cc 2024-12-07 20:29:55 +08:00
774db61377 add output 1-100 2024-12-07 20:25:22 +08:00
4 changed files with 90 additions and 1 deletions

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

@ -0,0 +1,5 @@
{
"recommendations": [
"ms-vscode.cmake-tools"
]
}

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

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

View File

@ -2,8 +2,15 @@
using namespace std;
int main() {
void output(){ //循环输出1-100
for(int i = 1; i <= 100; i++){
cout << i << endl;
}
return;
}
int main() {
cout << "100" << endl;
cout << "hello world!" << endl;
cout << "hello too!" << endl;
return 0;

View File

@ -0,0 +1,72 @@
/*
muduo网络库给用户提供了两个主要的类
TcpServer
TcpClient
epoll+线
I/O的代码和业务代码区分开
*/
#include <muduo/net/TcpServer.h>
#include <muduo/net/EventLoop.h>
#include <iostream>
#include <functional>
using namespace std;
using namespace muduo;
using namespace muduo::net;
using namespace placeholders;
/*
muduo网络库开发服务器程序
1.TcpServer对象
2.
3.TcpServer构造函数需要什么参数ChatServer的构造函数
4.
5.线,muduo库会自己分配I/O线程和worker线程
*/
class ChatServer{
public:
ChatServer(EventLoop* loop,
const InetAddress& listenAddr,
const string& nameArg)
:_server(loop,listenAddr,nameArg),_loop(loop)
{
//给服务器注册用户连接的创建和断开回调
_server.setConnectionCallback(std::bind(&ChatServer::onConnection, this, _1));
//给服务器注册用户读写事件的回调
_server.setMessageCallback(std::bind(&ChatServer::onMessage, this, _1, _2, _3));
//设置服务器端的线程数量 1个I/O线程 3个worker线程
_server.setThreadNum(4);
}
void start(){
_server.start();
}
private:
void onConnection(const TcpConnectionPtr&)
{
}
void onMessage(const TcpConnectionPtr& conn,
Buffer* buffer,
Timestamp time)
{
}
TcpServer _server;
EventLoop* _loop;
};