diff --git a/HISTORY b/HISTORY index 52cb95f..68deda8 100644 --- a/HISTORY +++ b/HISTORY @@ -1,8 +1,9 @@ -Version 1.76 2024-11-01 +Version 1.76 2025-01-27 * get_mounted_filesystems act as program df * add function get_statfs_by_path * add function is_rotational_device_by_path + * conn_pool_get_connection_ex add parameter: shared Version 1.75 2024-09-22 * task init callback support extra argument diff --git a/src/connection_pool.c b/src/connection_pool.c index b8e8b06..9e6498d 100644 --- a/src/connection_pool.c +++ b/src/connection_pool.c @@ -651,7 +651,8 @@ static ConnectionInfo *get_conn(ConnectionPool *cp, static ConnectionInfo *get_connection(ConnectionPool *cp, const ConnectionInfo *conn, const string_t *key, - const uint32_t hash_code, const char *service_name, int *err_no) + const uint32_t hash_code, const char *service_name, + const bool shared, int *err_no) { ConnectionBucket *bucket; ConnectionManager *cm; @@ -662,6 +663,10 @@ static ConnectionInfo *get_connection(ConnectionPool *cp, if ((cm=find_manager(cp, bucket, key, true)) != NULL) { ci = get_conn(cp, cm, &bucket->lock, conn, service_name, err_no); + if (ci != NULL) + { + ci->shared = shared; + } } else { @@ -673,7 +678,8 @@ static ConnectionInfo *get_connection(ConnectionPool *cp, } ConnectionInfo *conn_pool_get_connection_ex(ConnectionPool *cp, - const ConnectionInfo *conn, const char *service_name, int *err_no) + const ConnectionInfo *conn, const char *service_name, + const bool shared, int *err_no) { string_t key; int bytes; @@ -687,8 +693,9 @@ ConnectionInfo *conn_pool_get_connection_ex(ConnectionPool *cp, key.str = key_buff; conn_pool_get_key(conn, key.str, &key.len); hash_code = fc_simple_hash(key.str, key.len); - if (!cp->extra_params.tls.enabled) { - return get_connection(cp, conn, &key, hash_code, service_name, err_no); + if (!cp->extra_params.tls.enabled || !shared) { + return get_connection(cp, conn, &key, hash_code, + service_name, shared, err_no); } htable = pthread_getspecific(cp->tls_key); @@ -729,7 +736,7 @@ ConnectionInfo *conn_pool_get_connection_ex(ConnectionPool *cp, return node->conn; } else { if ((ci=get_connection(cp, conn, &key, hash_code, - service_name, err_no)) == NULL) + service_name, shared, err_no)) == NULL) { return NULL; } @@ -757,10 +764,11 @@ int conn_pool_close_connection_ex(ConnectionPool *cp, key.str = key_buff; conn_pool_get_key(conn, key.str, &key.len); hash_code = fc_simple_hash(key.str, key.len); - if (!cp->extra_params.tls.enabled) { + if (!cp->extra_params.tls.enabled || !conn->shared) { return close_connection(cp, conn, &key, hash_code, bForce); } + //thread local logic if (!bForce) { return 0; } diff --git a/src/connection_pool.h b/src/connection_pool.h index fe436b6..b3f670c 100644 --- a/src/connection_pool.h +++ b/src/connection_pool.h @@ -50,7 +50,8 @@ typedef enum { typedef struct { int sock; uint16_t port; - short af; //address family, AF_INET, AF_INET6 or AF_UNSPEC for auto dedect + uint8_t af; //address family, AF_INET, AF_INET6 or AF_UNSPEC for auto dedect + bool shared; //for connection pool FCCommunicationType comm_type; bool validate_flag; //for connection pool char ip_addr[IP_ADDRESS_SIZE]; @@ -299,14 +300,16 @@ void conn_pool_destroy(ConnectionPool *cp); * cp: the ConnectionPool * conn: the connection * service_name: the service name to log +* shared: if the connection shared * err_no: return the the errno, 0 for success * return != NULL for success, NULL for error */ ConnectionInfo *conn_pool_get_connection_ex(ConnectionPool *cp, - const ConnectionInfo *conn, const char *service_name, int *err_no); + const ConnectionInfo *conn, const char *service_name, + const bool shared, int *err_no); #define conn_pool_get_connection(cp, conn, err_no) \ - conn_pool_get_connection_ex(cp, conn, NULL, err_no) + conn_pool_get_connection_ex(cp, conn, NULL, false, err_no) #define conn_pool_close_connection(cp, conn) \ conn_pool_close_connection_ex(cp, conn, false) diff --git a/src/sockopt.c b/src/sockopt.c index 4cb59f0..ccdc9f4 100644 --- a/src/sockopt.c +++ b/src/sockopt.c @@ -1201,7 +1201,7 @@ char *getHostnameByIp(const char *szIpAddr, char *buff, const int bufferSize) } in_addr_64_t getIpaddrByNameEx(const char *name, char *buff, - const int bufferSize, short *af) + const int bufferSize, uint8_t *af) { struct addrinfo hints, *res, *p; struct in_addr addr4; diff --git a/src/sockopt.h b/src/sockopt.h index 0fde8b1..e53ea56 100644 --- a/src/sockopt.h +++ b/src/sockopt.h @@ -391,12 +391,12 @@ char *getHostnameByIp(const char *szIpAddr, char *buff, const int bufferSize); * return: in_addr_64_t, INADDR_NONE for fail */ in_addr_64_t getIpaddrByNameEx(const char *name, char *buff, - const int bufferSize, short *af); + const int bufferSize, uint8_t *af); static inline in_addr_64_t getIpaddrByName(const char *name, char *buff, const int bufferSize) { - short af; + uint8_t af; return getIpaddrByNameEx(name, buff, bufferSize, &af); }