-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.h
executable file
·70 lines (55 loc) · 1.52 KB
/
server.h
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
67
68
69
70
#include<iostream>
#include <map>
#include <string>
#include "lib.h"
#include <vector>
#include <tr1/unordered_map>
#include "TaskManager.h"
#include <set>
#ifndef __SERVER
#define __SERVER
typedef int clientFd;
typedef int groupId;
struct Stats
{
};
struct TimerStruct{
clientFd cFd;
groupId gId;
void *eventEngine;
};
struct EventEngine
{
int lisSerFd, eventFd, nfds, cliFd;
struct epoll_event event;
struct epoll_event *events;
std::tr1::unordered_map<clientFd, groupId> clientGroupMap;
std::tr1::unordered_map<groupId, std::set<clientFd> > groupClientMap;
std::tr1::unordered_map<groupId, TaskManager*> groupTaskManagerMap;
// std::tr1::unordered_map<groupId, std::vector<std::string> > groupMsgMap;
std::tr1::unordered_map<groupId, std::vector<std::string> >::iterator it;
std::vector<TimerStruct* > timerEvents;
EventEngine():cliFd(-1)
{
}
int start(char *, int);
void run();
void listenNewConn(int fd);
void listenClient(int fd);
void registerClient(char *buf, int count,int fd);
timer_t registerTimerEvent(int taskId, groupId gId, int seconds,void* eventEngine);
void deRegisterTimerEvent(timer_t timerid);
void addTimerEvent(void * timerStruct);
void deregisterClient(int fd);
void sendMessage(clientFd cFd, char* buff, int size);
int getFreeGroup();
std::set<clientFd>& getClients(groupId gId);
void registerTaskManager(groupId gId, TaskManager *tm);
void deregisterTaskManager(groupId gId);
~EventEngine()
{
free(events);
close (lisSerFd);
}
};
#endif