-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (52 loc) · 1.58 KB
/
main.cpp
File metadata and controls
67 lines (52 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Created by yangning on 17-10-25.
//
// Descriprion :
//
// Copyright (c) yangning All rights reserved.
//
#include "EventLoopThreadPool.h"
#include "gtest/gtest.h"
#include "tcp_server.h"
#include "tcp_connection.h"
#include "event_loop.h"
#include "Server.h"
#define __TESTING
int main(int argc, char* argv[])
{
#ifdef __TESTING
//::testing::FLAGS_gtest_color="yes";
//::testing::InitGoogleTest(&argc, argv);
net::EventLoop loop(net::POLL);
Server server(&loop,0);
server.run();
/**
net::EventLoop loop(net::POLL);
//单线程环境
//net::EventLoopThreadPool loop_pool(&loop,0);
//EXPECT_EQ(&loop,loop_pool.getNextLoop());
//net::EventLoopThreadPool loop_pool(&loop,4);
//EXPECT_EQ(&loop,loop_pool.getNextLoop());
net::TcpServer tcpServer(kPort,&loop,1);
loop.assertInLoopThread();
tcpServer.setClienCloseCallBack([](net::TcpConnectionPtr connection){
printf("fd is %d closed \n",connection->getFd());
});
tcpServer.setClientReadCallBack([](net::TcpConnection& connection,net::SocketBuf* buf){
connection.send(buf->readBegin(),buf->readableBytes());
//printf("%s",buf->readBegin());
buf->skip(buf->readableBytes());
});
tcpServer.setClienErrorCallBack([](){
printErrorMsg("error");
});
tcpServer.setNewConnCallBack([](int fd, const IpAddress& ipAddress) {
printf("a new connection fd is %d ,ip : %s port : %d \n", fd, ipAddress.ip.c_str(), ipAddress.port);
});
tcpServer.serverStart();
*/// return RUN_ALL_TESTS();
return 0;
#else
return 0;
#endif //__TESTING
}