fujuntang
2021-11-30 490948a0d52a3ad7b3f94525a982fc7012d06011
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
#ifndef __NET_SERVER_MODE_SOCKET_H__
#define __NET_SERVER_MODE_SOCKET_H__
 
#include "usg_common.h"
#include "shm_mod_socket.h"
#include "socket_io.h"
 
class NetModServerSocket {
 
    struct net_mod_msg_t {
        int key;
        socket_mod_t mod;
        size_t content_size;
        void * content;
        size_t topic_size;
        void * topic;
    };
 
    struct pool{ /* Represents a pool of connected descriptors */ //line:conc:echoservers:beginpool
      int maxfd;        /* Largest descriptor in read_set */
      fd_set read_set;  /* Set of all active descriptors */
      fd_set ready_set; /* Subset of descriptors ready for reading  */
      int nready;       /* Number of ready descriptors from select */
      int maxi;         /* Highwater index into client array */
      int clientfd[FD_SETSIZE];    /* Set of active descriptors */
     // rio_t clientrio[FD_SETSIZE]; /* Set of active read buffers */
    } ; 
 
private:
    int listenfd;
    int port;
    ShmModSocket shmModSocket;
    pool pool;
 
    void *buf;
    void *topic_buf;
    char *response_buf;
 
  size_t max_buf;
  size_t max_topic_buf;
  size_t max_response_buf;
 
 
    void init_pool(int listenfd);
    void add_client(int connfd);
    void check_clients();
    int process_client(int connfd);
 
public:
 
    NetModServerSocket(int port);
    
    /*
     * 启动 server
     * @return 0 success, 其他 failture
    */
    int start();
    ~NetModServerSocket();
 
};
 
 
#endif