-
Notifications
You must be signed in to change notification settings - Fork 3
/
Server.cpp
47 lines (33 loc) · 1.14 KB
/
Server.cpp
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
//
// Created by yangning on 18-1-15.
//
// Descriprion :
//
// Copyright (c) yangning All rights reserved.
//
#include "Server.h"
#include "tcp_server.h"
void Server::run()
{
tcpServer_.setClienErrorCallBack([](){
printErrorMsg("error");
});
tcpServer_.setClientReadCallBack([&](net::TcpConnectionPtr connection,net::SocketBuf* buf){
auto ite = sessionMap_.find(connection->getFd())->second;//[net::TcpConnectionPtr(&connection)];
ite.handleRequest(connection,buf);
});
tcpServer_.setClienCloseCallBack([](net::TcpConnectionPtr connection){
printf("fd is %d closed \n",connection->getFd());
});
tcpServer_.setNewConnCallBack([&](int fd, const IpAddress& ipAddress,net::TcpConnectionPtr& conn_ptr) {
//Session session(ipAddress);
sessionMap_.insert(std::make_pair(fd,Session(ipAddress)));
//sessionMap_[conn_ptr]=std::move(session);
printf("a new connection fd is %d ,ip : %s port : %d \n", fd, ipAddress.ip.c_str(), ipAddress.port);
});
tcpServer_.serverStart();
}
Server::Server(net::EventLoop* loop,size_t thread_num)
:tcpServer_(9000,loop,thread_num)
{
}