add functions getIpAndPort and getPeerIpAndPort
parent
da4c9a2581
commit
c2837fde5f
3
HISTORY
3
HISTORY
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
Version 1.44 2020-03-23
|
Version 1.44 2020-03-26
|
||||||
* add test file src/tests/test_pthread_lock.c
|
* add test file src/tests/test_pthread_lock.c
|
||||||
* add uniq_skiplist.[hc]
|
* add uniq_skiplist.[hc]
|
||||||
* add function split_string_ex
|
* add function split_string_ex
|
||||||
|
|
@ -22,6 +22,7 @@ Version 1.44 2020-03-23
|
||||||
* pthread_func.[hc] add functions: create_work_threads_ex and fc_create_thread
|
* pthread_func.[hc] add functions: create_work_threads_ex and fc_create_thread
|
||||||
* sched_add_entries use temp ScheduleArray for rare case
|
* sched_add_entries use temp ScheduleArray for rare case
|
||||||
* add function common_blocked_queue_return_nodes
|
* add function common_blocked_queue_return_nodes
|
||||||
|
* add functions getIpAndPort and getPeerIpAndPort
|
||||||
|
|
||||||
Version 1.43 2019-12-25
|
Version 1.43 2019-12-25
|
||||||
* replace function call system to getExecResult,
|
* replace function call system to getExecResult,
|
||||||
|
|
|
||||||
|
|
@ -538,6 +538,17 @@ int free_queue_realloc_buffer(struct fast_task_info *pTask,
|
||||||
return task_queue_realloc_buffer(&g_free_queue, pTask, expect_size);
|
return task_queue_realloc_buffer(&g_free_queue, pTask, expect_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int free_queue_set_max_buffer_size(struct fast_task_info *pTask)
|
||||||
|
{
|
||||||
|
return task_queue_set_buffer_size(&g_free_queue, pTask,
|
||||||
|
g_free_queue.max_buff_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
int free_queue_realloc_max_buffer(struct fast_task_info *pTask)
|
||||||
|
{
|
||||||
|
return task_queue_realloc_buffer(&g_free_queue, pTask,
|
||||||
|
g_free_queue.max_buff_size);
|
||||||
|
}
|
||||||
int task_queue_push(struct fast_task_queue *pQueue, \
|
int task_queue_push(struct fast_task_queue *pQueue, \
|
||||||
struct fast_task_info *pTask)
|
struct fast_task_info *pTask)
|
||||||
{
|
{
|
||||||
|
|
@ -716,4 +727,3 @@ int task_queue_realloc_buffer(struct fast_task_queue *pQueue,
|
||||||
|
|
||||||
return _realloc_buffer(pTask, new_size, true);
|
return _realloc_buffer(pTask, new_size, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ struct fast_task_info
|
||||||
int size; //alloc size
|
int size; //alloc size
|
||||||
int length; //data length
|
int length; //data length
|
||||||
int offset; //current offset
|
int offset; //current offset
|
||||||
|
uint16_t port; //client port
|
||||||
char nio_stage; //stage for network IO
|
char nio_stage; //stage for network IO
|
||||||
bool canceled; //if task canceled
|
bool canceled; //if task canceled
|
||||||
int64_t req_count; //request count
|
int64_t req_count; //request count
|
||||||
|
|
@ -116,6 +117,10 @@ int free_queue_set_buffer_size(struct fast_task_info *pTask,
|
||||||
int free_queue_realloc_buffer(struct fast_task_info *pTask,
|
int free_queue_realloc_buffer(struct fast_task_info *pTask,
|
||||||
const int expect_size);
|
const int expect_size);
|
||||||
|
|
||||||
|
int free_queue_set_max_buffer_size(struct fast_task_info *pTask);
|
||||||
|
|
||||||
|
int free_queue_realloc_max_buffer(struct fast_task_info *pTask);
|
||||||
|
|
||||||
int task_queue_init(struct fast_task_queue *pQueue);
|
int task_queue_init(struct fast_task_queue *pQueue);
|
||||||
int task_queue_push(struct fast_task_queue *pQueue, \
|
int task_queue_push(struct fast_task_queue *pQueue, \
|
||||||
struct fast_task_info *pTask);
|
struct fast_task_info *pTask);
|
||||||
|
|
|
||||||
|
|
@ -152,15 +152,23 @@ int ioevent_loop(struct nio_thread_data *pThreadData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pThreadData->notify.enabled) {
|
if (pThreadData->notify.enabled)
|
||||||
|
{
|
||||||
int64_t n;
|
int64_t n;
|
||||||
if ((n=__sync_fetch_and_add(&pThreadData->notify.counter, 0)) != 0) {
|
if ((n=__sync_fetch_and_add(&pThreadData->notify.counter, 0)) != 0)
|
||||||
logInfo("file: "__FILE__", line: %d, "
|
{
|
||||||
"n ==== %"PRId64, __LINE__, n);
|
|
||||||
__sync_fetch_and_sub(&pThreadData->notify.counter, n);
|
__sync_fetch_and_sub(&pThreadData->notify.counter, n);
|
||||||
|
/*
|
||||||
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
|
"n ==== %"PRId64", now: %"PRId64,
|
||||||
|
__LINE__, n, __sync_fetch_and_add(
|
||||||
|
&pThreadData->notify.counter, 0));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pThreadData->thread_loop_callback != NULL) {
|
|
||||||
|
if (pThreadData->thread_loop_callback != NULL)
|
||||||
|
{
|
||||||
pThreadData->thread_loop_callback(pThreadData);
|
pThreadData->thread_loop_callback(pThreadData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -768,6 +768,38 @@ in_addr_t getIpaddr(getnamefunc getname, int sock, \
|
||||||
return ((struct sockaddr_in *)&addr)->sin_addr.s_addr; //DO NOT support IPv6
|
return ((struct sockaddr_in *)&addr)->sin_addr.s_addr; //DO NOT support IPv6
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getIpAndPort(getnamefunc getname, int sock,
|
||||||
|
char *buff, const int bufferSize, int *port)
|
||||||
|
{
|
||||||
|
struct sockaddr addr;
|
||||||
|
socklen_t addrlen;
|
||||||
|
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
addrlen = sizeof(addr);
|
||||||
|
|
||||||
|
if (getname(sock, &addr, &addrlen) != 0)
|
||||||
|
{
|
||||||
|
*buff = '\0';
|
||||||
|
return errno != 0 ? errno : EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addrlen > 0)
|
||||||
|
{
|
||||||
|
fc_inet_ntop(&addr, buff, bufferSize);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*buff = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addr.sa_family == AF_INET) {
|
||||||
|
*port = ntohs(((struct sockaddr_in *)&addr)->sin_port);
|
||||||
|
} else {
|
||||||
|
*port = ntohs(((struct sockaddr_in6 *)&addr)->sin6_port);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
char *getHostnameByIp(const char *szIpAddr, char *buff, const int bufferSize)
|
char *getHostnameByIp(const char *szIpAddr, char *buff, const int bufferSize)
|
||||||
{
|
{
|
||||||
struct hostent *ent;
|
struct hostent *ent;
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,12 @@ typedef int (*tcprecvdata_exfunc)(int sock, void *data, const int size, \
|
||||||
#define getPeerIpaddr(sock, buff, bufferSize) \
|
#define getPeerIpaddr(sock, buff, bufferSize) \
|
||||||
getIpaddr(getpeername, sock, buff, bufferSize)
|
getIpaddr(getpeername, sock, buff, bufferSize)
|
||||||
|
|
||||||
|
#define getSockIpAddPort(sock, buff, bufferSize, port) \
|
||||||
|
getIpAndPort(getsockname, sock, buff, bufferSize, port)
|
||||||
|
|
||||||
|
#define getPeerIpAddPort(sock, buff, bufferSize, port) \
|
||||||
|
getIpAndPort(getpeername, sock, buff, bufferSize, port)
|
||||||
|
|
||||||
/** get a line from socket
|
/** get a line from socket
|
||||||
* parameters:
|
* parameters:
|
||||||
* sock: the socket
|
* sock: the socket
|
||||||
|
|
@ -260,6 +266,18 @@ int tcpprintkeepalive(int fd);
|
||||||
in_addr_t getIpaddr(getnamefunc getname, int sock, \
|
in_addr_t getIpaddr(getnamefunc getname, int sock, \
|
||||||
char *buff, const int bufferSize);
|
char *buff, const int bufferSize);
|
||||||
|
|
||||||
|
/** get ip address
|
||||||
|
* parameters:
|
||||||
|
* getname: the function name, should be getpeername or getsockname
|
||||||
|
* sock: the socket
|
||||||
|
* buff: buffer to store the ip address
|
||||||
|
* bufferSize: the buffer size (max bytes)
|
||||||
|
* port: return the port
|
||||||
|
* return: error no, 0 success, != 0 fail
|
||||||
|
*/
|
||||||
|
int getIpAndPort(getnamefunc getname, int sock,
|
||||||
|
char *buff, const int bufferSize, int *port);
|
||||||
|
|
||||||
/** get hostname by it's ip address
|
/** get hostname by it's ip address
|
||||||
* parameters:
|
* parameters:
|
||||||
* szIpAddr: the ip address
|
* szIpAddr: the ip address
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,8 @@ int main(int argc, char *argv[])
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("child done, time used: %"PRId64" ms\n", get_current_time_ms() - start_time);
|
printf("child done, LOOP: %d, time used: %"PRId64" ms\n",
|
||||||
|
LOOP, get_current_time_ms() - start_time);
|
||||||
} else {
|
} else {
|
||||||
printf("the child proccess: %d\n", pid);
|
printf("the child proccess: %d\n", pid);
|
||||||
start_time = get_current_time_ms();
|
start_time = get_current_time_ms();
|
||||||
|
|
@ -68,8 +69,9 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("parent done, time used: %"PRId64" ms\n", get_current_time_ms() - start_time);
|
printf("parent done, LOOP: %d, time used: %"PRId64" ms\n",
|
||||||
sleep(5);
|
LOOP, get_current_time_ms() - start_time);
|
||||||
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ int main(int argc, char *argv[])
|
||||||
int k;
|
int k;
|
||||||
int64_t sum;
|
int64_t sum;
|
||||||
int64_t start_time;
|
int64_t start_time;
|
||||||
|
char time_buff[32];
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
|
|
||||||
log_init();
|
log_init();
|
||||||
|
|
@ -41,7 +42,8 @@ int main(int argc, char *argv[])
|
||||||
__sync_add_and_fetch(&sum, k);
|
__sync_add_and_fetch(&sum, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("atom add, sum: %"PRId64", time used: %"PRId64" ms\n",
|
printf("atom add, LOOP_COUNT: %s, sum: %"PRId64", time used: "
|
||||||
|
"%"PRId64" ms\n", int_to_comma_str(LOOP_COUNT, time_buff),
|
||||||
sum, get_current_time_ms() - start_time);
|
sum, get_current_time_ms() - start_time);
|
||||||
|
|
||||||
start_time = get_current_time_ms();
|
start_time = get_current_time_ms();
|
||||||
|
|
@ -52,7 +54,8 @@ int main(int argc, char *argv[])
|
||||||
pthread_mutex_unlock(&lock);
|
pthread_mutex_unlock(&lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("locked add, sum: %"PRId64", time used: %"PRId64" ms\n",
|
printf("locked add, LOOP_COUNT: %s, sum: %"PRId64", time used: "
|
||||||
|
"%"PRId64" ms\n", int_to_comma_str(LOOP_COUNT, time_buff),
|
||||||
sum, get_current_time_ms() - start_time);
|
sum, get_current_time_ms() - start_time);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue