Compare commits

...

3 Commits

Author SHA1 Message Date
Hongcai Deng f9eded7a4b
Merge a16fde8070 into 13fc696432 2025-01-27 11:22:54 +08:00
YuQing 13fc696432 conn_pool_get_connection_ex add parameter: shared 2025-01-27 10:55:26 +08:00
Hongcai Deng a16fde8070 fix: compile error when build .so using .a
```
src/libfastcommon.a(hash.o): relocation R_X86_64_32 against `.data' can not be used when making a shared object; recompile with -fPIC
```

env: Ubuntu 14.04, gcc 4.8
2017-01-29 14:20:18 +08:00
6 changed files with 26 additions and 14 deletions

View File

@ -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

View File

@ -66,7 +66,7 @@ libfastcommon.a: $(FAST_STATIC_OBJS)
.c:
$(COMPILE) -o $@ $< $(FAST_STATIC_OBJS) $(LIB_PATH) $(INC_PATH)
.c.o:
$(COMPILE) -c -o $@ $< $(INC_PATH)
$(COMPILE) -c -fPIC -o $@ $< $(INC_PATH)
.c.lo:
$(COMPILE) -c -fPIC -o $@ $< $(INC_PATH)
install:

View File

@ -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;
}

View File

@ -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)

View File

@ -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;

View File

@ -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);
}