add function conn_pool_get_connection_ex to support service name
parent
630a6a2af6
commit
1f83e66306
|
|
@ -186,8 +186,8 @@ static inline void conn_pool_get_key(const ConnectionInfo *conn, char *key, int
|
||||||
*key_len = sprintf(key, "%s_%u", conn->ip_addr, conn->port);
|
*key_len = sprintf(key, "%s_%u", conn->ip_addr, conn->port);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionInfo *conn_pool_get_connection(ConnectionPool *cp,
|
ConnectionInfo *conn_pool_get_connection_ex(ConnectionPool *cp,
|
||||||
const ConnectionInfo *conn, int *err_no)
|
const ConnectionInfo *conn, const char *service_name, int *err_no)
|
||||||
{
|
{
|
||||||
char key[INET6_ADDRSTRLEN + 8];
|
char key[INET6_ADDRSTRLEN + 8];
|
||||||
int key_len;
|
int key_len;
|
||||||
|
|
@ -236,11 +236,11 @@ ConnectionInfo *conn_pool_get_connection(ConnectionPool *cp,
|
||||||
(cm->total_count >= cp->max_count_per_entry))
|
(cm->total_count >= cp->max_count_per_entry))
|
||||||
{
|
{
|
||||||
*err_no = ENOSPC;
|
*err_no = ENOSPC;
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"connections: %d of server %s:%u " \
|
"connections: %d of %s%sserver %s:%u exceed limit: %d",
|
||||||
"exceed limit: %d", __LINE__, \
|
__LINE__, cm->total_count, service_name != NULL ?
|
||||||
cm->total_count, conn->ip_addr, \
|
service_name : "", service_name != NULL ? " " : "",
|
||||||
conn->port, cp->max_count_per_entry);
|
conn->ip_addr, conn->port, cp->max_count_per_entry);
|
||||||
pthread_mutex_unlock(&cm->lock);
|
pthread_mutex_unlock(&cm->lock);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -269,8 +269,8 @@ ConnectionInfo *conn_pool_get_connection(ConnectionPool *cp,
|
||||||
node->conn->socket_domain = cp->socket_domain;
|
node->conn->socket_domain = cp->socket_domain;
|
||||||
node->conn->sock = -1;
|
node->conn->sock = -1;
|
||||||
node->conn->validate_flag = false;
|
node->conn->validate_flag = false;
|
||||||
*err_no = conn_pool_connect_server(node->conn,
|
*err_no = conn_pool_connect_server_ex1(node->conn,
|
||||||
cp->connect_timeout);
|
service_name, cp->connect_timeout, NULL, true);
|
||||||
if (*err_no == 0 && cp->connect_done_callback.func != NULL)
|
if (*err_no == 0 && cp->connect_done_callback.func != NULL)
|
||||||
{
|
{
|
||||||
*err_no = cp->connect_done_callback.func(node->conn,
|
*err_no = cp->connect_done_callback.func(node->conn,
|
||||||
|
|
|
||||||
|
|
@ -172,11 +172,15 @@ void conn_pool_destroy(ConnectionPool *cp);
|
||||||
* parameters:
|
* parameters:
|
||||||
* cp: the ConnectionPool
|
* cp: the ConnectionPool
|
||||||
* conn: the connection
|
* conn: the connection
|
||||||
|
* service_name: the service name to log
|
||||||
* err_no: return the the errno, 0 for success
|
* err_no: return the the errno, 0 for success
|
||||||
* return != NULL for success, NULL for error
|
* return != NULL for success, NULL for error
|
||||||
*/
|
*/
|
||||||
ConnectionInfo *conn_pool_get_connection(ConnectionPool *cp,
|
ConnectionInfo *conn_pool_get_connection_ex(ConnectionPool *cp,
|
||||||
const ConnectionInfo *conn, int *err_no);
|
const ConnectionInfo *conn, const char *service_name, int *err_no);
|
||||||
|
|
||||||
|
#define conn_pool_get_connection(cp, conn, err_no) \
|
||||||
|
conn_pool_get_connection_ex(cp, conn, NULL, err_no)
|
||||||
|
|
||||||
#define conn_pool_close_connection(cp, conn) \
|
#define conn_pool_close_connection(cp, conn) \
|
||||||
conn_pool_close_connection_ex(cp, conn, false)
|
conn_pool_close_connection_ex(cp, conn, false)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue