jimi-wzq
2021-01-12 48e47110397c894716525db219e53300c08f64dd
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
/**
 * 配合thread local使用的connection pool
 */
 
#ifndef __NET_CONN_POOL_H__
#define __NET_CONN_POOL_H__ 
 
 
#include "usg_common.h"
#include <poll.h>
 
#define OPEN_MAX 1024
 
#define ADDRSTRLEN (NI_MAXHOST + NI_MAXSERV + 10) 
 
class NetConnPool{ /* Represents a pool of connected descriptors */ 
public:
  int nready;       /* Number of ready descriptors from select */
  int maxi;         /* Highwater index into client array */
  struct pollfd conns[OPEN_MAX];
  std::map<std::string, int> connectionMap;
 
    NetConnPool() ;
    ~NetConnPool() ;
    /**
     * 获取连接
    */
    int getConn(const char *host, int port);
    /**
     * 放回连接
    */
    void putConn(int connfd);
    /**
     * 关闭连接
     */
    void closeConn(int connfd);
 
 
     
}; 
 
#endif