chenke
2017-08-09 2a12817d4ae31a591f788f3fbb82916e385e9e2d
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
#ifndef _EV_SERVER_H_
#define _EV_SERVER_H_
 
#include <stddef.h>
#include <stdint.h>
#include "ev_proto.h"
 
#ifndef SERVER_PORT
#define SERVER_PORT 5432
#endif
#define REUSEADDR_ON 1
#define CLIENT_BUFFER_MAX 1*1024*1024 // 1MB
#define CLIENT_READ_TIMES_MAX 100
#define CLIENT_MAX 100 // max count of clients connected //#todo not support
 
struct EVClientStub
{
    int id;
    const uint8_t* recvBuff;
    const size_t recvBuffSize;
    uint8_t* sendBuff;
    size_t sendBuffSize;
    bool deleteSendBuff;
    
    EVClientStub() : 
        id(-1), 
        recvBuff(nullptr), recvBuffSize(0), 
        sendBuff(nullptr), sendBuffSize(0), deleteSendBuff(false)
    {
    }
    
    EVClientStub(const uint8_t* _recvBuff, size_t _recvBuffSize) : 
        id(-1), 
        recvBuff(_recvBuff), recvBuffSize(_recvBuffSize), 
        sendBuff(nullptr), sendBuffSize(0), deleteSendBuff(false)
    {
    }
};
 
typedef bool (*evclient_proc_t)(EVClientStub& client);
extern evclient_proc_t evclient_proc;
 
//#define USER_DEFINE_EVCLIENT_PROC
 
int server_main(int argc, char **argv);
void server_stop();
 
void ev_send_packet(EVClientStub& client);
void ev_send_status_packet(EVClientStub& client, EVPStatus::EVPS status);
 
#endif