/**
|
* 配合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
|