Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ce77983f
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1181
Star
22014
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
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 {
WIN32_FIND_DATA
findFileData
;
}
TdDirEntry
;
typedef
struct
TdDir
{
TdDirEntry
dirEntry
;
HANDLE
hFind
;
...
...
@@ -59,7 +58,7 @@ void wordfree(wordexp_t *pwordexp) {}
#include <wordexp.h>
typedef
struct
dirent
dirent
;
typedef
struct
DIR
TdDir
;
typedef
struct
DIR
TdDir
;
typedef
struct
dirent
TdDirEntry
;
#endif
...
...
@@ -78,14 +77,14 @@ void taosRemoveDir(const char *dirname) {
taosRemoveDir
(
filename
);
}
else
{
(
void
)
taosRemoveFile
(
filename
);
//printf("file:%s is removed\n", filename);
//
printf("file:%s is removed\n", filename);
}
}
taosCloseDir
(
&
pDir
);
rmdir
(
dirname
);
//printf("dir:%s is removed\n", dirname);
//
printf("dir:%s is removed\n", dirname);
return
;
}
...
...
@@ -102,8 +101,8 @@ int32_t taosMkDir(const char *dirname) {
int32_t
taosMulMkDir
(
const
char
*
dirname
)
{
if
(
dirname
==
NULL
)
return
-
1
;
char
*
temp
=
strdup
(
dirname
);
char
*
pos
=
temp
;
char
*
temp
=
strdup
(
dirname
);
char
*
pos
=
temp
;
int32_t
code
=
0
;
if
(
strncmp
(
temp
,
"/"
,
1
)
==
0
)
{
...
...
@@ -111,8 +110,8 @@ int32_t taosMulMkDir(const char *dirname) {
}
else
if
(
strncmp
(
temp
,
"./"
,
2
)
==
0
)
{
pos
+=
2
;
}
for
(
;
*
pos
!=
'\0'
;
pos
++
)
{
for
(;
*
pos
!=
'\0'
;
pos
++
)
{
if
(
*
pos
==
'/'
)
{
*
pos
=
'\0'
;
code
=
mkdir
(
temp
,
0755
);
...
...
@@ -123,7 +122,7 @@ int32_t taosMulMkDir(const char *dirname) {
*
pos
=
'/'
;
}
}
if
(
*
(
pos
-
1
)
!=
'/'
)
{
code
=
mkdir
(
temp
,
0755
);
if
(
code
<
0
&&
errno
!=
EEXIST
)
{
...
...
@@ -145,7 +144,7 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
TdDirPtr
pDir
=
taosOpenDir
(
dirname
);
if
(
pDir
==
NULL
)
return
;
int64_t
sec
=
taosGetTimestampSec
();
int64_t
sec
=
taosGetTimestampSec
();
TdDirEntryPtr
de
=
NULL
;
while
((
de
=
taosReadDir
(
pDir
))
!=
NULL
)
{
...
...
@@ -173,9 +172,9 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
int32_t
days
=
(
int32_t
)(
TABS
(
sec
-
fileSec
)
/
86400
+
1
);
if
(
days
>
keepDays
)
{
(
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
{
//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) {
int32_t
taosExpandDir
(
const
char
*
dirname
,
char
*
outname
,
int32_t
maxlen
)
{
wordexp_t
full_path
;
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
);
return
-
1
;
}
...
...
@@ -228,9 +227,9 @@ bool taosIsDir(const char *dirname) {
return
false
;
}
char
*
taosDirName
(
char
*
name
)
{
char
*
taosDirName
(
char
*
name
)
{
#ifdef WINDOWS
char
Drive1
[
MAX_PATH
],
Dir1
[
MAX_PATH
];
char
Drive1
[
MAX_PATH
],
Dir1
[
MAX_PATH
];
_splitpath
(
name
,
Drive1
,
Dir1
,
NULL
,
NULL
);
size_t
dirNameLen
=
strlen
(
Drive1
)
+
strlen
(
Dir1
);
if
(
dirNameLen
>
0
)
{
...
...
@@ -242,13 +241,13 @@ char* taosDirName(char *name) {
#endif
}
char
*
taosDirEntryBaseName
(
char
*
name
)
{
char
*
taosDirEntryBaseName
(
char
*
name
)
{
#ifdef WINDOWS
char
Filename1
[
MAX_PATH
],
Ext1
[
MAX_PATH
];
_splitpath
(
name
,
NULL
,
NULL
,
Filename1
,
Ext1
);
return
name
+
(
strlen
(
name
)
-
strlen
(
Filename1
)
-
strlen
(
Ext1
));
#else
return
(
char
*
)
basename
(
name
);
return
(
char
*
)
basename
(
name
);
#endif
}
...
...
@@ -258,8 +257,8 @@ TdDirPtr taosOpenDir(const char *dirname) {
}
#ifdef WINDOWS
char
szFind
[
MAX_PATH
];
//这是要找的
HANDLE
hFind
;
char
szFind
[
MAX_PATH
];
//这是要找的
HANDLE
hFind
;
TdDirPtr
pDir
=
taosMemoryMalloc
(
sizeof
(
TdDir
));
...
...
@@ -275,7 +274,6 @@ TdDirPtr taosOpenDir(const char *dirname) {
#else
return
(
TdDirPtr
)
opendir
(
dirname
);
#endif
}
TdDirEntryPtr
taosReadDir
(
TdDirPtr
pDir
)
{
...
...
@@ -286,9 +284,9 @@ TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
if
(
!
FindNextFile
(
pDir
->
hFind
,
&
(
pDir
->
dirEntry
.
findFileData
)))
{
return
NULL
;
}
return
(
TdDirEntryPtr
)
&
(
pDir
->
dirEntry
.
findFileData
);
return
(
TdDirEntryPtr
)
&
(
pDir
->
dirEntry
.
findFileData
);
#else
return
(
TdDirEntryPtr
)
readdir
((
DIR
*
)
pDir
);
return
(
TdDirEntryPtr
)
readdir
((
DIR
*
)
pDir
);
#endif
}
...
...
@@ -299,18 +297,18 @@ bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) {
#ifdef WINDOWS
return
(
pDirEntry
->
findFileData
.
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
)
!=
0
;
#else
return
(((
dirent
*
)
pDirEntry
)
->
d_type
&
DT_DIR
)
!=
0
;
return
(((
dirent
*
)
pDirEntry
)
->
d_type
&
DT_DIR
)
!=
0
;
#endif
}
char
*
taosGetDirEntryName
(
TdDirEntryPtr
pDirEntry
)
{
char
*
taosGetDirEntryName
(
TdDirEntryPtr
pDirEntry
)
{
if
(
pDirEntry
==
NULL
)
{
return
NULL
;
}
#ifdef WINDOWS
return
pDirEntry
->
findFileData
.
cFileName
;
#else
return
((
dirent
*
)
pDirEntry
)
->
d_name
;
return
((
dirent
*
)
pDirEntry
)
->
d_name
;
#endif
}
...
...
@@ -324,7 +322,7 @@ int32_t taosCloseDir(TdDirPtr *ppDir) {
*
ppDir
=
NULL
;
return
0
;
#else
closedir
((
DIR
*
)
*
ppDir
);
closedir
((
DIR
*
)
*
ppDir
);
*
ppDir
=
NULL
;
return
0
;
#endif
...
...
source/os/src/osSocket.c
浏览文件 @
ce77983f
...
...
@@ -28,6 +28,7 @@
#else
#include <arpa/inet.h>
#include <fcntl.h>
#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/ip.h>
...
...
@@ -638,6 +639,72 @@ int32_t taosKeepTcpAlive(TdSocketPtr pSocket) {
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
)
{
struct
sockaddr_in
serverAdd
;
SocketFd
fd
;
...
...
@@ -677,13 +744,8 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
taosCloseSocket
(
&
pSocket
);
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
);
return
tru
e
;
return
0
==
taosValidIp
(
ip
)
?
true
:
fals
e
;
}
TdSocketServerPtr
taosOpenTcpServerSocket
(
uint32_t
ip
,
uint16_t
port
)
{
struct
sockaddr_in
serverAdd
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录