Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ce77983f
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ce77983f
编写于
5月 09, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(rpc): fix invalide fqdn
上级
129819db
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
92 addition
and
32 deletion
+92
-32
source/os/src/osDir.c
source/os/src/osDir.c
+24
-26
source/os/src/osSocket.c
source/os/src/osSocket.c
+68
-6
未找到文件。
source/os/src/osDir.c
浏览文件 @
ce77983f
...
@@ -26,7 +26,6 @@ typedef struct TdDirEntry {
...
@@ -26,7 +26,6 @@ typedef struct TdDirEntry {
WIN32_FIND_DATA
findFileData
;
WIN32_FIND_DATA
findFileData
;
}
TdDirEntry
;
}
TdDirEntry
;
typedef
struct
TdDir
{
typedef
struct
TdDir
{
TdDirEntry
dirEntry
;
TdDirEntry
dirEntry
;
HANDLE
hFind
;
HANDLE
hFind
;
...
@@ -78,14 +77,14 @@ void taosRemoveDir(const char *dirname) {
...
@@ -78,14 +77,14 @@ void taosRemoveDir(const char *dirname) {
taosRemoveDir
(
filename
);
taosRemoveDir
(
filename
);
}
else
{
}
else
{
(
void
)
taosRemoveFile
(
filename
);
(
void
)
taosRemoveFile
(
filename
);
//printf("file:%s is removed\n", filename);
//
printf("file:%s is removed\n", filename);
}
}
}
}
taosCloseDir
(
&
pDir
);
taosCloseDir
(
&
pDir
);
rmdir
(
dirname
);
rmdir
(
dirname
);
//printf("dir:%s is removed\n", dirname);
//
printf("dir:%s is removed\n", dirname);
return
;
return
;
}
}
...
@@ -102,8 +101,8 @@ int32_t taosMkDir(const char *dirname) {
...
@@ -102,8 +101,8 @@ int32_t taosMkDir(const char *dirname) {
int32_t
taosMulMkDir
(
const
char
*
dirname
)
{
int32_t
taosMulMkDir
(
const
char
*
dirname
)
{
if
(
dirname
==
NULL
)
return
-
1
;
if
(
dirname
==
NULL
)
return
-
1
;
char
*
temp
=
strdup
(
dirname
);
char
*
temp
=
strdup
(
dirname
);
char
*
pos
=
temp
;
char
*
pos
=
temp
;
int32_t
code
=
0
;
int32_t
code
=
0
;
if
(
strncmp
(
temp
,
"/"
,
1
)
==
0
)
{
if
(
strncmp
(
temp
,
"/"
,
1
)
==
0
)
{
...
@@ -112,7 +111,7 @@ int32_t taosMulMkDir(const char *dirname) {
...
@@ -112,7 +111,7 @@ int32_t taosMulMkDir(const char *dirname) {
pos
+=
2
;
pos
+=
2
;
}
}
for
(
;
*
pos
!=
'\0'
;
pos
++
)
{
for
(;
*
pos
!=
'\0'
;
pos
++
)
{
if
(
*
pos
==
'/'
)
{
if
(
*
pos
==
'/'
)
{
*
pos
=
'\0'
;
*
pos
=
'\0'
;
code
=
mkdir
(
temp
,
0755
);
code
=
mkdir
(
temp
,
0755
);
...
@@ -173,9 +172,9 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
...
@@ -173,9 +172,9 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
int32_t
days
=
(
int32_t
)(
TABS
(
sec
-
fileSec
)
/
86400
+
1
);
int32_t
days
=
(
int32_t
)(
TABS
(
sec
-
fileSec
)
/
86400
+
1
);
if
(
days
>
keepDays
)
{
if
(
days
>
keepDays
)
{
(
void
)
taosRemoveFile
(
filename
);
(
void
)
taosRemoveFile
(
filename
);
//printf("file:%s is removed, days:%d keepDays:%d", filename, days, keepDays);
//
printf("file:%s is removed, days:%d keepDays:%d", filename, days, keepDays);
}
else
{
}
else
{
//printf("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays);
//
printf("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays);
}
}
}
}
}
}
...
@@ -187,7 +186,7 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
...
@@ -187,7 +186,7 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
int32_t
taosExpandDir
(
const
char
*
dirname
,
char
*
outname
,
int32_t
maxlen
)
{
int32_t
taosExpandDir
(
const
char
*
dirname
,
char
*
outname
,
int32_t
maxlen
)
{
wordexp_t
full_path
;
wordexp_t
full_path
;
if
(
0
!=
wordexp
(
dirname
,
&
full_path
,
0
))
{
if
(
0
!=
wordexp
(
dirname
,
&
full_path
,
0
))
{
//printf("failed to expand path:%s since %s", dirname, strerror(errno));
//
printf("failed to expand path:%s since %s", dirname, strerror(errno));
wordfree
(
&
full_path
);
wordfree
(
&
full_path
);
return
-
1
;
return
-
1
;
}
}
...
@@ -228,7 +227,7 @@ bool taosIsDir(const char *dirname) {
...
@@ -228,7 +227,7 @@ bool taosIsDir(const char *dirname) {
return
false
;
return
false
;
}
}
char
*
taosDirName
(
char
*
name
)
{
char
*
taosDirName
(
char
*
name
)
{
#ifdef WINDOWS
#ifdef WINDOWS
char
Drive1
[
MAX_PATH
],
Dir1
[
MAX_PATH
];
char
Drive1
[
MAX_PATH
],
Dir1
[
MAX_PATH
];
_splitpath
(
name
,
Drive1
,
Dir1
,
NULL
,
NULL
);
_splitpath
(
name
,
Drive1
,
Dir1
,
NULL
,
NULL
);
...
@@ -242,13 +241,13 @@ char* taosDirName(char *name) {
...
@@ -242,13 +241,13 @@ char* taosDirName(char *name) {
#endif
#endif
}
}
char
*
taosDirEntryBaseName
(
char
*
name
)
{
char
*
taosDirEntryBaseName
(
char
*
name
)
{
#ifdef WINDOWS
#ifdef WINDOWS
char
Filename1
[
MAX_PATH
],
Ext1
[
MAX_PATH
];
char
Filename1
[
MAX_PATH
],
Ext1
[
MAX_PATH
];
_splitpath
(
name
,
NULL
,
NULL
,
Filename1
,
Ext1
);
_splitpath
(
name
,
NULL
,
NULL
,
Filename1
,
Ext1
);
return
name
+
(
strlen
(
name
)
-
strlen
(
Filename1
)
-
strlen
(
Ext1
));
return
name
+
(
strlen
(
name
)
-
strlen
(
Filename1
)
-
strlen
(
Ext1
));
#else
#else
return
(
char
*
)
basename
(
name
);
return
(
char
*
)
basename
(
name
);
#endif
#endif
}
}
...
@@ -275,7 +274,6 @@ TdDirPtr taosOpenDir(const char *dirname) {
...
@@ -275,7 +274,6 @@ TdDirPtr taosOpenDir(const char *dirname) {
#else
#else
return
(
TdDirPtr
)
opendir
(
dirname
);
return
(
TdDirPtr
)
opendir
(
dirname
);
#endif
#endif
}
}
TdDirEntryPtr
taosReadDir
(
TdDirPtr
pDir
)
{
TdDirEntryPtr
taosReadDir
(
TdDirPtr
pDir
)
{
...
@@ -286,9 +284,9 @@ TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
...
@@ -286,9 +284,9 @@ TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
if
(
!
FindNextFile
(
pDir
->
hFind
,
&
(
pDir
->
dirEntry
.
findFileData
)))
{
if
(
!
FindNextFile
(
pDir
->
hFind
,
&
(
pDir
->
dirEntry
.
findFileData
)))
{
return
NULL
;
return
NULL
;
}
}
return
(
TdDirEntryPtr
)
&
(
pDir
->
dirEntry
.
findFileData
);
return
(
TdDirEntryPtr
)
&
(
pDir
->
dirEntry
.
findFileData
);
#else
#else
return
(
TdDirEntryPtr
)
readdir
((
DIR
*
)
pDir
);
return
(
TdDirEntryPtr
)
readdir
((
DIR
*
)
pDir
);
#endif
#endif
}
}
...
@@ -299,18 +297,18 @@ bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) {
...
@@ -299,18 +297,18 @@ bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) {
#ifdef WINDOWS
#ifdef WINDOWS
return
(
pDirEntry
->
findFileData
.
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
)
!=
0
;
return
(
pDirEntry
->
findFileData
.
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
)
!=
0
;
#else
#else
return
(((
dirent
*
)
pDirEntry
)
->
d_type
&
DT_DIR
)
!=
0
;
return
(((
dirent
*
)
pDirEntry
)
->
d_type
&
DT_DIR
)
!=
0
;
#endif
#endif
}
}
char
*
taosGetDirEntryName
(
TdDirEntryPtr
pDirEntry
)
{
char
*
taosGetDirEntryName
(
TdDirEntryPtr
pDirEntry
)
{
if
(
pDirEntry
==
NULL
)
{
if
(
pDirEntry
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
#ifdef WINDOWS
#ifdef WINDOWS
return
pDirEntry
->
findFileData
.
cFileName
;
return
pDirEntry
->
findFileData
.
cFileName
;
#else
#else
return
((
dirent
*
)
pDirEntry
)
->
d_name
;
return
((
dirent
*
)
pDirEntry
)
->
d_name
;
#endif
#endif
}
}
...
@@ -324,7 +322,7 @@ int32_t taosCloseDir(TdDirPtr *ppDir) {
...
@@ -324,7 +322,7 @@ int32_t taosCloseDir(TdDirPtr *ppDir) {
*
ppDir
=
NULL
;
*
ppDir
=
NULL
;
return
0
;
return
0
;
#else
#else
closedir
((
DIR
*
)
*
ppDir
);
closedir
((
DIR
*
)
*
ppDir
);
*
ppDir
=
NULL
;
*
ppDir
=
NULL
;
return
0
;
return
0
;
#endif
#endif
...
...
source/os/src/osSocket.c
浏览文件 @
ce77983f
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
#else
#else
#include <arpa/inet.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <fcntl.h>
#include <net/if.h>
#include <netdb.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip.h>
...
@@ -638,6 +639,72 @@ int32_t taosKeepTcpAlive(TdSocketPtr pSocket) {
...
@@ -638,6 +639,72 @@ int32_t taosKeepTcpAlive(TdSocketPtr pSocket) {
return
0
;
return
0
;
}
}
int
taosGetLocalIp
(
const
char
*
eth
,
char
*
ip
)
{
#if defined(WINDOWS)
// DO NOTHAING
return
0
;
#else
int
fd
;
struct
ifreq
ifr
;
struct
sockaddr_in
sin
;
fd
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
);
if
(
-
1
==
fd
)
{
return
-
1
;
}
strncpy
(
ifr
.
ifr_name
,
eth
,
IFNAMSIZ
);
ifr
.
ifr_name
[
IFNAMSIZ
-
1
]
=
0
;
if
(
ioctl
(
fd
,
SIOCGIFADDR
,
&
ifr
)
<
0
)
{
taosCloseSocketNoCheck1
(
fd
);
return
-
1
;
}
memcpy
(
&
sin
,
&
ifr
.
ifr_addr
,
sizeof
(
sin
));
snprintf
(
ip
,
64
,
"%s"
,
inet_ntoa
(
sin
.
sin_addr
));
taosCloseSocketNoCheck1
(
fd
);
#endif
return
0
;
}
int
taosValidIp
(
uint32_t
ip
)
{
#if defined(WINDOWS)
// DO NOTHAING
return
0
;
#else
int
ret
=
-
1
;
int
fd
;
struct
ifconf
ifconf
;
char
buf
[
512
]
=
{
0
};
ifconf
.
ifc_len
=
512
;
ifconf
.
ifc_buf
=
buf
;
if
((
fd
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
))
<
0
)
{
return
-
1
;
}
ioctl
(
fd
,
SIOCGIFCONF
,
&
ifconf
);
struct
ifreq
*
ifreq
=
(
struct
ifreq
*
)
ifconf
.
ifc_buf
;
for
(
int
i
=
(
ifconf
.
ifc_len
/
sizeof
(
struct
ifreq
));
i
>
0
;
i
--
)
{
char
ip_str
[
64
]
=
{
0
};
if
(
ifreq
->
ifr_flags
==
AF_INET
)
{
ret
=
taosGetLocalIp
(
ifreq
->
ifr_name
,
ip_str
);
if
(
ret
!=
0
)
{
break
;
}
ifreq
++
;
}
if
(
ip
==
(
uint32_t
)
taosInetAddr
(
ip_str
))
{
ret
=
0
;
break
;
}
}
taosCloseSocketNoCheck1
(
fd
);
return
ret
;
#endif
return
0
;
}
bool
taosValidIpAndPort
(
uint32_t
ip
,
uint16_t
port
)
{
bool
taosValidIpAndPort
(
uint32_t
ip
,
uint16_t
port
)
{
struct
sockaddr_in
serverAdd
;
struct
sockaddr_in
serverAdd
;
SocketFd
fd
;
SocketFd
fd
;
...
@@ -677,13 +744,8 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
...
@@ -677,13 +744,8 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
taosCloseSocket
(
&
pSocket
);
taosCloseSocket
(
&
pSocket
);
return
false
;
return
false
;
}
}
if
(
listen
(
pSocket
->
fd
,
1024
)
<
0
)
{
// printf("listen tcp server socket failed, 0x%x:%hu(%s)", ip, port, strerror(errno));
taosCloseSocket
(
&
pSocket
);
return
false
;
}
taosCloseSocket
(
&
pSocket
);
taosCloseSocket
(
&
pSocket
);
return
tru
e
;
return
0
==
taosValidIp
(
ip
)
?
true
:
fals
e
;
}
}
TdSocketServerPtr
taosOpenTcpServerSocket
(
uint32_t
ip
,
uint16_t
port
)
{
TdSocketServerPtr
taosOpenTcpServerSocket
(
uint32_t
ip
,
uint16_t
port
)
{
struct
sockaddr_in
serverAdd
;
struct
sockaddr_in
serverAdd
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录