Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3588761c
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3588761c
编写于
3月 07, 2022
作者:
wafwerar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-13760]<fix>: libuv replace socket error.
上级
2f792722
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
131 addition
and
121 deletion
+131
-121
include/os/osSocket.h
include/os/osSocket.h
+6
-7
source/os/CMakeLists.txt
source/os/CMakeLists.txt
+4
-1
source/os/src/osSocket.c
source/os/src/osSocket.c
+119
-112
source/util/CMakeLists.txt
source/util/CMakeLists.txt
+1
-0
source/util/src/thttp.c
source/util/src/thttp.c
+1
-1
未找到文件。
include/os/osSocket.h
浏览文件 @
3588761c
...
...
@@ -63,8 +63,6 @@ int32_t taosCloseSocket(SocketFd fd);
void
taosShutDownSocketRD
(
SOCKET
fd
);
void
taosShutDownSocketWR
(
SOCKET
fd
);
int32_t
taosSetNonblocking
(
SOCKET
sock
,
int32_t
on
);
void
taosIgnSIGPIPE
();
void
taosSetMaskSIGPIPE
();
int32_t
taosSetSockOpt
(
SOCKET
socketfd
,
int32_t
level
,
int32_t
optname
,
void
*
optval
,
int32_t
optlen
);
int32_t
taosGetSockOpt
(
SOCKET
socketfd
,
int32_t
level
,
int32_t
optname
,
void
*
optval
,
int32_t
*
optlen
);
...
...
@@ -94,14 +92,15 @@ SOCKET taosOpenTcpClientSocket(uint32_t ip, uint16_t port, uint32_t localIp);
SOCKET
taosOpenTcpServerSocket
(
uint32_t
ip
,
uint16_t
port
);
int32_t
taosKeepTcpAlive
(
SOCKET
sockFd
);
int32_t
taosGetFqdn
(
char
*
);
uint32_t
taosGetIpv4FromFqdn
(
const
char
*
);
void
tinet_ntoa
(
char
*
ipstr
,
uint32_t
ip
);
uint32_t
ip2uint
(
const
char
*
const
ip_addr
);
#endif
void
taosBlockSIGPIPE
();
uint32_t
taosGetIpv4FromFqdn
(
const
char
*
);
int32_t
taosGetFqdn
(
char
*
);
void
tinet_ntoa
(
char
*
ipstr
,
uint32_t
ip
);
uint32_t
ip2uint
(
const
char
*
const
ip_addr
);
void
taosIgnSIGPIPE
();
void
taosSetMaskSIGPIPE
();
#ifdef __cplusplus
}
...
...
source/os/CMakeLists.txt
浏览文件 @
3588761c
...
...
@@ -7,4 +7,7 @@ target_include_directories(
)
target_link_libraries
(
os pthread dl rt m
)
\ No newline at end of file
)
if
(
${
BUILD_WITH_UV
}
)
add_definitions
(
-DUSE_UV
)
endif
(
${
BUILD_TEST
}
)
\ No newline at end of file
source/os/src/osSocket.c
浏览文件 @
3588761c
...
...
@@ -131,18 +131,8 @@ int32_t taosSetNonblocking(SOCKET sock, int32_t on) {
return
0
;
}
void
taosIgnSIGPIPE
()
{
signal
(
SIGPIPE
,
SIG_IGN
);
}
void
taosSetMaskSIGPIPE
()
{
sigset_t
signal_mask
;
sigemptyset
(
&
signal_mask
);
sigaddset
(
&
signal_mask
,
SIGPIPE
);
int32_t
rc
=
pthread_sigmask
(
SIG_SETMASK
,
&
signal_mask
,
NULL
);
if
(
rc
!=
0
)
{
//printf("failed to setmask SIGPIPE");
}
}
#endif
...
...
@@ -223,9 +213,6 @@ int32_t taosSetNonblocking(SOCKET sock, int32_t on) {
return
0
;
}
void
taosIgnSIGPIPE
()
{}
void
taosSetMaskSIGPIPE
()
{}
int32_t
taosSetSockOpt
(
SOCKET
socketfd
,
int32_t
level
,
int32_t
optname
,
void
*
optval
,
int32_t
optlen
)
{
if
(
level
==
SOL_SOCKET
&&
optname
==
TCP_KEEPCNT
)
{
return
0
;
...
...
@@ -282,98 +269,6 @@ uint64_t htonll(uint64_t val) { return (((uint64_t)htonl(val)) << 32) + htonl(va
#define TCP_CONN_TIMEOUT 3000 // conn timeout
int32_t
taosGetFqdn
(
char
*
fqdn
)
{
char
hostname
[
1024
];
hostname
[
1023
]
=
'\0'
;
if
(
gethostname
(
hostname
,
1023
)
==
-
1
)
{
//printf("failed to get hostname, reason:%s", strerror(errno));
return
-
1
;
}
struct
addrinfo
hints
=
{
0
};
struct
addrinfo
*
result
=
NULL
;
#ifdef __APPLE__
// on macosx, hostname -f has the form of xxx.local
// which will block getaddrinfo for a few seconds if AI_CANONNAME is set
// thus, we choose AF_INET (ipv4 for the moment) to make getaddrinfo return
// immediately
hints
.
ai_family
=
AF_INET
;
#else // __APPLE__
hints
.
ai_flags
=
AI_CANONNAME
;
#endif // __APPLE__
int32_t
ret
=
getaddrinfo
(
hostname
,
NULL
,
&
hints
,
&
result
);
if
(
!
result
)
{
//printf("failed to get fqdn, code:%d, reason:%s", ret, gai_strerror(ret));
return
-
1
;
}
#ifdef __APPLE__
// refer to comments above
strcpy
(
fqdn
,
hostname
);
#else // __APPLE__
strcpy
(
fqdn
,
result
->
ai_canonname
);
#endif // __APPLE__
freeaddrinfo
(
result
);
return
0
;
}
uint32_t
taosGetIpv4FromFqdn
(
const
char
*
fqdn
)
{
struct
addrinfo
hints
=
{
0
};
hints
.
ai_family
=
AF_INET
;
hints
.
ai_socktype
=
SOCK_STREAM
;
struct
addrinfo
*
result
=
NULL
;
int32_t
ret
=
getaddrinfo
(
fqdn
,
NULL
,
&
hints
,
&
result
);
if
(
result
)
{
struct
sockaddr
*
sa
=
result
->
ai_addr
;
struct
sockaddr_in
*
si
=
(
struct
sockaddr_in
*
)
sa
;
struct
in_addr
ia
=
si
->
sin_addr
;
uint32_t
ip
=
ia
.
s_addr
;
freeaddrinfo
(
result
);
return
ip
;
}
else
{
#ifdef EAI_SYSTEM
if
(
ret
==
EAI_SYSTEM
)
{
//printf("failed to get the ip address, fqdn:%s, since:%s", fqdn, strerror(errno));
}
else
{
//printf("failed to get the ip address, fqdn:%s, since:%s", fqdn, gai_strerror(ret));
}
#else
//printf("failed to get the ip address, fqdn:%s, since:%s", fqdn, gai_strerror(ret));
#endif
return
0xFFFFFFFF
;
}
}
// Function converting an IP address string to an uint32_t.
uint32_t
ip2uint
(
const
char
*
const
ip_addr
)
{
char
ip_addr_cpy
[
20
];
char
ip
[
5
];
tstrncpy
(
ip_addr_cpy
,
ip_addr
,
sizeof
(
ip_addr_cpy
));
char
*
s_start
,
*
s_end
;
s_start
=
ip_addr_cpy
;
s_end
=
ip_addr_cpy
;
int32_t
k
;
for
(
k
=
0
;
*
s_start
!=
'\0'
;
s_start
=
s_end
)
{
for
(
s_end
=
s_start
;
*
s_end
!=
'.'
&&
*
s_end
!=
'\0'
;
s_end
++
)
{
}
if
(
*
s_end
==
'.'
)
{
*
s_end
=
'\0'
;
s_end
++
;
}
ip
[
k
++
]
=
(
char
)
atoi
(
s_start
);
}
ip
[
k
]
=
'\0'
;
return
*
((
uint32_t
*
)
ip
);
}
int32_t
taosWriteMsg
(
SOCKET
fd
,
void
*
buf
,
int32_t
nbytes
)
{
int32_t
nleft
,
nwritten
;
char
*
ptr
=
(
char
*
)
buf
;
...
...
@@ -754,10 +649,6 @@ SOCKET taosOpenTcpServerSocket(uint32_t ip, uint16_t port) {
return
sockFd
;
}
void
tinet_ntoa
(
char
*
ipstr
,
uint32_t
ip
)
{
sprintf
(
ipstr
,
"%d.%d.%d.%d"
,
ip
&
0xFF
,
(
ip
>>
8
)
&
0xFF
,
(
ip
>>
16
)
&
0xFF
,
ip
>>
24
);
}
#define COPY_SIZE 32768
// sendfile shall be used
...
...
@@ -799,8 +690,9 @@ int64_t taosCopyFds(SOCKET sfd, int32_t dfd, int64_t len) {
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
void
taosBlockSIGPIPE
()
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#else
sigset_t
signal_mask
;
sigemptyset
(
&
signal_mask
);
sigaddset
(
&
signal_mask
,
SIGPIPE
);
...
...
@@ -808,7 +700,122 @@ void taosBlockSIGPIPE() {
if
(
rc
!=
0
)
{
//printf("failed to block SIGPIPE");
}
#endif
}
uint32_t
taosGetIpv4FromFqdn
(
const
char
*
fqdn
)
{
struct
addrinfo
hints
=
{
0
};
hints
.
ai_family
=
AF_INET
;
hints
.
ai_socktype
=
SOCK_STREAM
;
struct
addrinfo
*
result
=
NULL
;
int32_t
ret
=
getaddrinfo
(
fqdn
,
NULL
,
&
hints
,
&
result
);
if
(
result
)
{
struct
sockaddr
*
sa
=
result
->
ai_addr
;
struct
sockaddr_in
*
si
=
(
struct
sockaddr_in
*
)
sa
;
struct
in_addr
ia
=
si
->
sin_addr
;
uint32_t
ip
=
ia
.
s_addr
;
freeaddrinfo
(
result
);
return
ip
;
}
else
{
#ifdef EAI_SYSTEM
if
(
ret
==
EAI_SYSTEM
)
{
//printf("failed to get the ip address, fqdn:%s, since:%s", fqdn, strerror(errno));
}
else
{
//printf("failed to get the ip address, fqdn:%s, since:%s", fqdn, gai_strerror(ret));
}
#else
void
taosBlockSIGPIPE
()
{}
#endif
\ No newline at end of file
//printf("failed to get the ip address, fqdn:%s, since:%s", fqdn, gai_strerror(ret));
#endif
return
0xFFFFFFFF
;
}
}
int32_t
taosGetFqdn
(
char
*
fqdn
)
{
char
hostname
[
1024
];
hostname
[
1023
]
=
'\0'
;
if
(
gethostname
(
hostname
,
1023
)
==
-
1
)
{
//printf("failed to get hostname, reason:%s", strerror(errno));
return
-
1
;
}
struct
addrinfo
hints
=
{
0
};
struct
addrinfo
*
result
=
NULL
;
#ifdef __APPLE__
// on macosx, hostname -f has the form of xxx.local
// which will block getaddrinfo for a few seconds if AI_CANONNAME is set
// thus, we choose AF_INET (ipv4 for the moment) to make getaddrinfo return
// immediately
hints
.
ai_family
=
AF_INET
;
#else // __APPLE__
hints
.
ai_flags
=
AI_CANONNAME
;
#endif // __APPLE__
int32_t
ret
=
getaddrinfo
(
hostname
,
NULL
,
&
hints
,
&
result
);
if
(
!
result
)
{
//printf("failed to get fqdn, code:%d, reason:%s", ret, gai_strerror(ret));
return
-
1
;
}
#ifdef __APPLE__
// refer to comments above
strcpy
(
fqdn
,
hostname
);
#else // __APPLE__
strcpy
(
fqdn
,
result
->
ai_canonname
);
#endif // __APPLE__
freeaddrinfo
(
result
);
return
0
;
}
// Function converting an IP address string to an uint32_t.
uint32_t
ip2uint
(
const
char
*
const
ip_addr
)
{
char
ip_addr_cpy
[
20
];
char
ip
[
5
];
tstrncpy
(
ip_addr_cpy
,
ip_addr
,
sizeof
(
ip_addr_cpy
));
char
*
s_start
,
*
s_end
;
s_start
=
ip_addr_cpy
;
s_end
=
ip_addr_cpy
;
int32_t
k
;
for
(
k
=
0
;
*
s_start
!=
'\0'
;
s_start
=
s_end
)
{
for
(
s_end
=
s_start
;
*
s_end
!=
'.'
&&
*
s_end
!=
'\0'
;
s_end
++
)
{
}
if
(
*
s_end
==
'.'
)
{
*
s_end
=
'\0'
;
s_end
++
;
}
ip
[
k
++
]
=
(
char
)
atoi
(
s_start
);
}
ip
[
k
]
=
'\0'
;
return
*
((
uint32_t
*
)
ip
);
}
void
tinet_ntoa
(
char
*
ipstr
,
uint32_t
ip
)
{
sprintf
(
ipstr
,
"%d.%d.%d.%d"
,
ip
&
0xFF
,
(
ip
>>
8
)
&
0xFF
,
(
ip
>>
16
)
&
0xFF
,
ip
>>
24
);
}
void
taosIgnSIGPIPE
()
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#else
signal
(
SIGPIPE
,
SIG_IGN
);
#endif
}
void
taosSetMaskSIGPIPE
()
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#else
sigset_t
signal_mask
;
sigemptyset
(
&
signal_mask
);
sigaddset
(
&
signal_mask
,
SIGPIPE
);
int32_t
rc
=
pthread_sigmask
(
SIG_SETMASK
,
&
signal_mask
,
NULL
);
if
(
rc
!=
0
)
{
//printf("failed to setmask SIGPIPE");
}
#endif
}
\ No newline at end of file
source/util/CMakeLists.txt
浏览文件 @
3588761c
...
...
@@ -17,6 +17,7 @@ if(${BUILD_WITH_UV})
util
PUBLIC uv_a
)
add_definitions
(
-DUSE_UV
)
endif
(
${
BUILD_TEST
}
)
if
(
${
BUILD_TEST
}
)
...
...
source/util/src/thttp.c
浏览文件 @
3588761c
...
...
@@ -128,7 +128,7 @@ static void clientConnCb(uv_connect_t* req, int32_t status) {
uv_close
((
uv_handle_t
*
)
req
->
handle
,
NULL
);
}
int32_t
taosSendHttpReport
(
const
char
*
server
,
uint16_t
port
,
c
onst
c
har
*
pCont
,
int32_t
contLen
,
EHttpCompFlag
flag
)
{
int32_t
taosSendHttpReport
(
const
char
*
server
,
uint16_t
port
,
char
*
pCont
,
int32_t
contLen
,
EHttpCompFlag
flag
)
{
uint32_t
ipv4
=
taosGetIpv4FromFqdn
(
server
);
if
(
ipv4
==
0xffffffff
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录