Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿啄debugIT
libfastcommon
提交
c2837fde
L
libfastcommon
项目概览
阿啄debugIT
/
libfastcommon
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libfastcommon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c2837fde
编写于
3月 26, 2020
作者:
Y
YuQing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add functions getIpAndPort and getPeerIpAndPort
上级
da4c9a25
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
91 addition
and
12 deletion
+91
-12
HISTORY
HISTORY
+2
-1
src/fast_task_queue.c
src/fast_task_queue.c
+11
-1
src/fast_task_queue.h
src/fast_task_queue.h
+5
-0
src/ioevent_loop.c
src/ioevent_loop.c
+13
-5
src/sockopt.c
src/sockopt.c
+32
-0
src/sockopt.h
src/sockopt.h
+18
-0
src/tests/test_pipe.c
src/tests/test_pipe.c
+5
-3
src/tests/test_pthread_lock.c
src/tests/test_pthread_lock.c
+5
-2
未找到文件。
HISTORY
浏览文件 @
c2837fde
Version 1.44 2020-03-2
3
Version 1.44 2020-03-2
6
* add test file src/tests/test_pthread_lock.c
* add uniq_skiplist.[hc]
* 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
* sched_add_entries use temp ScheduleArray for rare case
* add function common_blocked_queue_return_nodes
* add functions getIpAndPort and getPeerIpAndPort
Version 1.43 2019-12-25
* replace function call system to getExecResult,
...
...
src/fast_task_queue.c
浏览文件 @
c2837fde
...
...
@@ -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
);
}
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
,
\
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
);
}
src/fast_task_queue.h
浏览文件 @
c2837fde
...
...
@@ -71,6 +71,7 @@ struct fast_task_info
int
size
;
//alloc size
int
length
;
//data length
int
offset
;
//current offset
uint16_t
port
;
//client port
char
nio_stage
;
//stage for network IO
bool
canceled
;
//if task canceled
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
,
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_push
(
struct
fast_task_queue
*
pQueue
,
\
struct
fast_task_info
*
pTask
);
...
...
src/ioevent_loop.c
浏览文件 @
c2837fde
...
...
@@ -152,15 +152,23 @@ int ioevent_loop(struct nio_thread_data *pThreadData,
}
}
if
(
pThreadData
->
notify
.
enabled
)
{
if
(
pThreadData
->
notify
.
enabled
)
{
int64_t
n
;
if
((
n
=
__sync_fetch_and_add
(
&
pThreadData
->
notify
.
counter
,
0
))
!=
0
)
{
logInfo
(
"file: "
__FILE__
", line: %d, "
"n ==== %"
PRId64
,
__LINE__
,
n
);
if
((
n
=
__sync_fetch_and_add
(
&
pThreadData
->
notify
.
counter
,
0
))
!=
0
)
{
__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
);
}
}
...
...
src/sockopt.c
浏览文件 @
c2837fde
...
...
@@ -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
}
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
)
{
struct
hostent
*
ent
;
...
...
src/sockopt.h
浏览文件 @
c2837fde
...
...
@@ -92,6 +92,12 @@ typedef int (*tcprecvdata_exfunc)(int sock, void *data, const int size, \
#define getPeerIpaddr(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
* parameters:
* sock: the socket
...
...
@@ -260,6 +266,18 @@ int tcpprintkeepalive(int fd);
in_addr_t
getIpaddr
(
getnamefunc
getname
,
int
sock
,
\
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
* parameters:
* szIpAddr: the ip address
...
...
src/tests/test_pipe.c
浏览文件 @
c2837fde
...
...
@@ -52,7 +52,8 @@ int main(int argc, char *argv[])
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
{
printf
(
"the child proccess: %d
\n
"
,
pid
);
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
);
sleep
(
5
);
printf
(
"parent done, LOOP: %d, time used: %"
PRId64
" ms
\n
"
,
LOOP
,
get_current_time_ms
()
-
start_time
);
sleep
(
1
);
}
return
0
;
...
...
src/tests/test_pthread_lock.c
浏览文件 @
c2837fde
...
...
@@ -21,6 +21,7 @@ int main(int argc, char *argv[])
int
k
;
int64_t
sum
;
int64_t
start_time
;
char
time_buff
[
32
];
pthread_mutex_t
lock
;
log_init
();
...
...
@@ -41,7 +42,8 @@ int main(int argc, char *argv[])
__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
);
start_time
=
get_current_time_ms
();
...
...
@@ -52,7 +54,8 @@ int main(int argc, char *argv[])
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
);
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录