Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
XKZJ_WCL
TDengine
提交
1dcdccb7
T
TDengine
项目概览
XKZJ_WCL
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1dcdccb7
编写于
10月 11, 2019
作者:
S
slguan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enable the client to compile under darwin
上级
25ff54c9
变更
38
隐藏空白更改
内联
并排
Showing
38 changed file
with
925 addition
and
305 deletion
+925
-305
.gitignore
.gitignore
+1
-0
CMakeLists.txt
CMakeLists.txt
+26
-7
src/client/CMakeLists.txt
src/client/CMakeLists.txt
+22
-12
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+2
-2
src/client/src/tscAsync.c
src/client/src/tscAsync.c
+2
-2
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+1
-1
src/client/src/tscServer.c
src/client/src/tscServer.c
+17
-17
src/client/src/tscSql.c
src/client/src/tscSql.c
+7
-5
src/client/src/tscStream.c
src/client/src/tscStream.c
+2
-2
src/client/src/tscSystem.c
src/client/src/tscSystem.c
+1
-1
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+2
-2
src/inc/tmodule.h
src/inc/tmodule.h
+3
-2
src/inc/ttimer.h
src/inc/ttimer.h
+16
-0
src/inc/tutil.h
src/inc/tutil.h
+1
-77
src/kit/shell/CMakeLists.txt
src/kit/shell/CMakeLists.txt
+17
-8
src/kit/shell/inc/shellCommand.h
src/kit/shell/inc/shellCommand.h
+0
-1
src/kit/shell/src/shellEngine.c
src/kit/shell/src/shellEngine.c
+22
-20
src/kit/shell/src/shellLinux.c
src/kit/shell/src/shellLinux.c
+1
-0
src/kit/shell/src/shellMain.c
src/kit/shell/src/shellMain.c
+5
-0
src/os/CMakeLists.txt
src/os/CMakeLists.txt
+1
-0
src/os/darwin/CMakeLists.txt
src/os/darwin/CMakeLists.txt
+9
-0
src/os/darwin/inc/os.h
src/os/darwin/inc/os.h
+133
-0
src/os/darwin/src/tdarwin.c
src/os/darwin/src/tdarwin.c
+418
-0
src/os/linux/inc/os.h
src/os/linux/inc/os.h
+49
-1
src/os/linux/src/tlinux.c
src/os/linux/src/tlinux.c
+51
-22
src/os/linux/src/tsystem.c
src/os/linux/src/tsystem.c
+0
-0
src/os/windows/inc/os.h
src/os/windows/inc/os.h
+33
-1
src/os/windows/src/twindows.c
src/os/windows/src/twindows.c
+3
-5
src/os/windows/src/twintimer.c
src/os/windows/src/twintimer.c
+1
-1
src/rpc/CMakeLists.txt
src/rpc/CMakeLists.txt
+5
-0
src/util/CMakeLists.txt
src/util/CMakeLists.txt
+36
-0
src/util/src/tglobalcfg.c
src/util/src/tglobalcfg.c
+2
-2
src/util/src/thistogram.c
src/util/src/thistogram.c
+1
-1
src/util/src/tlog.c
src/util/src/tlog.c
+11
-11
src/util/src/tmodule.c
src/util/src/tmodule.c
+8
-8
src/util/src/tsched.c
src/util/src/tsched.c
+10
-10
src/util/src/tsocket.c
src/util/src/tsocket.c
+2
-4
src/util/src/ttimer.c
src/util/src/ttimer.c
+4
-80
未找到文件。
.gitignore
浏览文件 @
1dcdccb7
...
...
@@ -9,6 +9,7 @@ release/
target/
debs/
rpms/
mac/
*.pyc
*.tmp
src/connector/nodejs/node_modules/
...
...
CMakeLists.txt
浏览文件 @
1dcdccb7
...
...
@@ -25,17 +25,17 @@ SET(TD_ROOT_DIR ${PROJECT_SOURCE_DIR})
#
# Set macro definitions according to os platform
SET
(
TD_
OS_
WINDOWS FALSE
)
SET
(
TD_
OS_
LINUX FALSE
)
SET
(
TD_
OS_
ARM FALSE
)
SET
(
TD_
OS_MAC
FALSE
)
SET
(
TD_WINDOWS FALSE
)
SET
(
TD_LINUX FALSE
)
SET
(
TD_ARM FALSE
)
SET
(
TD_
DARWIN
FALSE
)
IF
(
${
CMAKE_SYSTEM_NAME
}
MATCHES
"Linux"
)
SET
(
TD_OS_DIR
${
PROJECT_SOURCE_DIR
}
/src/os/linux
)
SET
(
TD_LINUX TRUE
)
ADD_DEFINITIONS
(
-DLINUX
)
IF
(
${
CMAKE_CXX_COMPILER_ID
}
MATCHES
"Clang"
)
SET
(
COMMON_FLAGS
"-std=gnu99 -Wall -fPIC -malign-double -g -Wno-char-subscripts -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
ELSE
()
...
...
@@ -77,9 +77,28 @@ ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
EXIT
()
ENDIF
()
ELSE
()
ELSEIF
(
${
CMAKE_SYSTEM_NAME
}
MATCHES
"Darwin"
)
SET
(
TD_OS_DIR
${
PROJECT_SOURCE_DIR
}
/src/os/darwin
)
SET
(
TD_DARWIN TRUE
)
ADD_DEFINITIONS
(
-DDARWIN
)
SET
(
COMMON_FLAGS
"-std=gnu99 -Wall -fPIC -malign-double -g -Wno-char-subscripts -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-unused-variable -Wno-bitfield-constant-conversion"
)
SET
(
DEBUG_FLAGS
"-O0 -DDEBUG"
)
SET
(
RELEASE_FLAGS
"-O0"
)
ADD_DEFINITIONS
(
-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT
)
IF
(
${
CMAKE_SIZEOF_VOID_P
}
MATCHES 8
)
MESSAGE
(
STATUS
"The current platform is Darwin 64-bit"
)
ADD_DEFINITIONS
(
-D_M_X64
)
ELSE
()
MESSAGE
(
FATAL_ERROR
"The current platform is Darwin 32-bit, not supported yet"
)
EXIT
()
ENDIF
()
MESSAGE
(
FATAL_ERROR
"The current platform is not Linux or Windows, stop compile"
)
ELSE
()
MESSAGE
(
FATAL_ERROR
"The current platform is not Linux/MAC/Windows, stop compile"
)
EXIT
()
ENDIF
()
...
...
src/client/CMakeLists.txt
浏览文件 @
1dcdccb7
...
...
@@ -6,23 +6,20 @@ AUX_SOURCE_DIRECTORY(./src SRC)
INCLUDE_DIRECTORIES
(
inc jni
${
TD_ROOT_DIR
}
/src/inc
${
TD_OS_DIR
}
/inc
)
IF
(
TD_LINUX
)
# generate dynamic library (*.so)
ADD_LIBRARY
(
taos SHARED
${
SRC
}
)
ADD_LIBRARY
(
taos_static STATIC
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taos_static trpc tutil pthread m rt
)
TARGET_LINK_LIBRARIES
(
taos trpc tutil pthread m rt
)
INCLUDE_DIRECTORIES
(
${
TD_ROOT_DIR
}
/deps/jni/linux
)
# set the static lib name
ADD_LIBRARY
(
taos_static STATIC
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taos_static trpc tutil pthread m rt
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES OUTPUT_NAME
"taos_static"
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES CLEAN_DIRECT_OUTPUT 1
)
# enable static lib and so exists
INCLUDE_DIRECTORIES
(
${
TD_ROOT_DIR
}
/deps/jni/linux
)
# generate dynamic library (*.so)
ADD_LIBRARY
(
taos SHARED
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taos trpc tutil pthread m rt
)
SET_TARGET_PROPERTIES
(
taos PROPERTIES CLEAN_DIRECT_OUTPUT 1
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES CLEAN_DIRECT_OUTPUT 1
)
TARGET_LINK_LIBRARIES
(
taos_static trpc tutil pthread
)
TARGET_LINK_LIBRARIES
(
taos trpc tutil pthread
)
#set version of .so
#VERSION so version
#SOVERSION api version
...
...
@@ -41,10 +38,23 @@ ELSEIF (TD_WINDOWS)
ADD_LIBRARY
(
taos_static STATIC
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taos_static trpc tutil
)
# generate dynamic library (*.dll)
ADD_LIBRARY
(
taos SHARED
${
SRC
}
)
SET_TARGET_PROPERTIES
(
taos PROPERTIES LINK_FLAGS /DEF:
${
TD_ROOT_DIR
}
/src/client/src/taos.def
)
TARGET_LINK_LIBRARIES
(
taos trpc
)
ELSEIF
(
TD_DARWIN
)
INCLUDE_DIRECTORIES
(
${
TD_ROOT_DIR
}
/deps/jni/linux
)
ADD_LIBRARY
(
taos_static STATIC
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taos_static trpc tutil pthread m
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES OUTPUT_NAME
"taos_static"
)
# generate dynamic library (*.dylib)
ADD_LIBRARY
(
taos SHARED
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taos trpc tutil pthread m
)
ENDIF
()
src/client/inc/tsclient.h
浏览文件 @
1dcdccb7
...
...
@@ -310,8 +310,8 @@ typedef struct _sql_obj {
char
index
;
char
freed
:
4
;
char
listed
:
4
;
sem_t
rspSem
;
sem_t
emptyRspSem
;
tsem_t
rspSem
;
tsem_t
emptyRspSem
;
SSqlCmd
cmd
;
SSqlRes
res
;
...
...
src/client/src/tscAsync.c
浏览文件 @
1dcdccb7
...
...
@@ -460,7 +460,7 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
code
=
abs
(
code
);
pRes
->
code
=
code
;
tscTrace
(
"%p failed to renew meterMeta"
,
pSql
);
sem_post
(
&
pSql
->
rspSem
);
t
sem_post
(
&
pSql
->
rspSem
);
}
else
{
tscTrace
(
"%p renew meterMeta successfully, command:%d, code:%d, thandle:%p, retry:%d"
,
pSql
,
pSql
->
cmd
.
command
,
pSql
->
res
.
code
,
pSql
->
thandle
,
pSql
->
retry
);
...
...
@@ -471,7 +471,7 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
code
=
tscSendMsgToServer
(
pSql
);
if
(
code
!=
0
)
{
pRes
->
code
=
code
;
sem_post
(
&
pSql
->
rspSem
);
t
sem_post
(
&
pSql
->
rspSem
);
}
}
...
...
src/client/src/tscParseInsert.c
浏览文件 @
1dcdccb7
...
...
@@ -53,7 +53,7 @@
return TSDB_CODE_INVALID_SQL; \
} while (0)
static
enum
{
enum
{
TSDB_USE_SERVER_TS
=
0
,
TSDB_USE_CLI_TS
=
1
,
};
...
...
src/client/src/tscServer.c
浏览文件 @
1dcdccb7
...
...
@@ -357,7 +357,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
}
}
if
(
pSql
->
fp
==
NULL
)
sem_wait
(
&
pSql
->
emptyRspSem
);
if
(
pSql
->
fp
==
NULL
)
t
sem_wait
(
&
pSql
->
emptyRspSem
);
pRes
->
rspLen
=
0
;
if
(
pRes
->
code
!=
TSDB_CODE_QUERY_CANCELLED
)
{
...
...
@@ -402,7 +402,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
}
if
(
pSql
->
fp
==
NULL
)
{
sem_post
(
&
pSql
->
rspSem
);
t
sem_post
(
&
pSql
->
rspSem
);
}
else
{
if
(
pRes
->
code
==
TSDB_CODE_SUCCESS
&&
tscProcessMsgRsp
[
pCmd
->
command
])
code
=
(
*
tscProcessMsgRsp
[
pCmd
->
command
])(
pSql
);
...
...
@@ -493,11 +493,11 @@ int tscProcessSql(SSqlObj *pSql) {
}
if
(
fp
==
NULL
)
{
sem_post
(
&
pSql
->
emptyRspSem
);
sem_wait
(
&
pSql
->
rspSem
);
t
sem_post
(
&
pSql
->
emptyRspSem
);
t
sem_wait
(
&
pSql
->
rspSem
);
assert
(
pSql
->
cmd
.
vnodeIdx
==
0
);
sem_post
(
&
pSql
->
emptyRspSem
);
t
sem_post
(
&
pSql
->
emptyRspSem
);
// set the command flag must be after the semaphore been correctly set.
pSql
->
cmd
.
command
=
TSDB_SQL_RETRIEVE_METRIC
;
...
...
@@ -525,11 +525,11 @@ int tscProcessSql(SSqlObj *pSql) {
return
code
;
}
sem_wait
(
&
pSql
->
rspSem
);
t
sem_wait
(
&
pSql
->
rspSem
);
if
(
pRes
->
code
==
0
&&
tscProcessMsgRsp
[
pCmd
->
command
])
(
*
tscProcessMsgRsp
[
pCmd
->
command
])(
pSql
);
sem_post
(
&
pSql
->
emptyRspSem
);
t
sem_post
(
&
pSql
->
emptyRspSem
);
return
pRes
->
code
;
}
...
...
@@ -725,10 +725,10 @@ static void tscHandleSubRetrievalError(SRetrieveSupport *trsupport, SSqlObj *pSq
if
(
pPObj
->
fp
==
NULL
)
{
// sync query, wait for the master SSqlObj to proceed
sem_wait
(
&
pPObj
->
emptyRspSem
);
sem_wait
(
&
pPObj
->
emptyRspSem
);
t
sem_wait
(
&
pPObj
->
emptyRspSem
);
t
sem_wait
(
&
pPObj
->
emptyRspSem
);
sem_post
(
&
pPObj
->
rspSem
);
t
sem_post
(
&
pPObj
->
rspSem
);
pPObj
->
cmd
.
command
=
TSDB_SQL_RETRIEVE_METRIC
;
}
else
{
...
...
@@ -850,10 +850,10 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
tscFreeSubSqlObj
(
trsupport
,
pSql
);
if
(
pPObj
->
fp
==
NULL
)
{
sem_wait
(
&
pPObj
->
emptyRspSem
);
sem_wait
(
&
pPObj
->
emptyRspSem
);
t
sem_wait
(
&
pPObj
->
emptyRspSem
);
t
sem_wait
(
&
pPObj
->
emptyRspSem
);
sem_post
(
&
pPObj
->
rspSem
);
t
sem_post
(
&
pPObj
->
rspSem
);
}
else
{
// set the command flag must be after the semaphore been correctly set.
pPObj
->
cmd
.
command
=
TSDB_SQL_RETRIEVE_METRIC
;
...
...
@@ -2759,8 +2759,8 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId) {
tscTrace
(
"%p new pSqlObj:%p to get meterMeta"
,
pSql
,
pNew
);
if
(
pSql
->
fp
==
NULL
)
{
sem_init
(
&
pNew
->
rspSem
,
0
,
0
);
sem_init
(
&
pNew
->
emptyRspSem
,
0
,
1
);
t
sem_init
(
&
pNew
->
rspSem
,
0
,
0
);
t
sem_init
(
&
pNew
->
emptyRspSem
,
0
,
1
);
code
=
tscProcessSql
(
pNew
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
...
...
@@ -2911,8 +2911,8 @@ int tscGetMetricMeta(SSqlObj *pSql, char *meterId) {
tscTrace
(
"%p allocate new pSqlObj:%p to get metricMeta"
,
pSql
,
pNew
);
if
(
pSql
->
fp
==
NULL
)
{
sem_init
(
&
pNew
->
rspSem
,
0
,
0
);
sem_init
(
&
pNew
->
emptyRspSem
,
0
,
1
);
t
sem_init
(
&
pNew
->
rspSem
,
0
,
0
);
t
sem_init
(
&
pNew
->
emptyRspSem
,
0
,
1
);
code
=
tscProcessSql
(
pNew
);
pSql
->
cmd
.
pMetricMeta
=
taosGetDataFromCache
(
tscCacheHandle
,
tagstr
);
...
...
src/client/src/tscSql.c
浏览文件 @
1dcdccb7
...
...
@@ -63,7 +63,9 @@ TAOS *taos_connect_imp(char *ip, char *user, char *pass, char *db, int port, voi
}
if
(
ip
&&
ip
[
0
])
{
strcpy
(
tsServerIpStr
,
ip
);
if
(
ip
!=
tsServerIpStr
)
{
strcpy
(
tsServerIpStr
,
ip
);
}
tsServerIp
=
inet_addr
(
ip
);
}
...
...
@@ -97,8 +99,8 @@ TAOS *taos_connect_imp(char *ip, char *user, char *pass, char *db, int port, voi
memset
(
pSql
,
0
,
sizeof
(
SSqlObj
));
pSql
->
pTscObj
=
pObj
;
pSql
->
signature
=
pSql
;
sem_init
(
&
pSql
->
rspSem
,
0
,
0
);
sem_init
(
&
pSql
->
emptyRspSem
,
0
,
1
);
t
sem_init
(
&
pSql
->
rspSem
,
0
,
0
);
t
sem_init
(
&
pSql
->
emptyRspSem
,
0
,
1
);
pObj
->
pSql
=
pSql
;
pSql
->
fp
=
fp
;
pSql
->
param
=
param
;
...
...
@@ -601,7 +603,7 @@ int taos_errno(TAOS *taos) {
if
(
pObj
==
NULL
||
pObj
->
signature
!=
pObj
)
return
globalCode
;
if
(
pObj
->
pSql
->
res
.
code
==
-
1
)
if
(
(
int8_t
)(
pObj
->
pSql
->
res
.
code
)
==
-
1
)
code
=
TSDB_CODE_OTHERS
;
else
code
=
pObj
->
pSql
->
res
.
code
;
...
...
@@ -616,7 +618,7 @@ char *taos_errstr(TAOS *taos) {
if
(
pObj
==
NULL
||
pObj
->
signature
!=
pObj
)
return
tsError
[
globalCode
];
if
(
pObj
->
pSql
->
res
.
code
==
-
1
)
if
(
(
int8_t
)(
pObj
->
pSql
->
res
.
code
)
==
-
1
)
code
=
TSDB_CODE_OTHERS
;
else
code
=
pObj
->
pSql
->
res
.
code
;
...
...
src/client/src/tscStream.c
浏览文件 @
1dcdccb7
...
...
@@ -472,8 +472,8 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, char *sqlstr, void (*fp)(void *param,
return
NULL
;
}
sem_init
(
&
pSql
->
rspSem
,
0
,
0
);
sem_init
(
&
pSql
->
emptyRspSem
,
0
,
1
);
t
sem_init
(
&
pSql
->
rspSem
,
0
,
0
);
t
sem_init
(
&
pSql
->
emptyRspSem
,
0
,
1
);
SSqlInfo
SQLInfo
=
{
0
};
tSQLParse
(
&
SQLInfo
,
pSql
->
sqlstr
);
...
...
src/client/src/tscSystem.c
浏览文件 @
1dcdccb7
...
...
@@ -82,7 +82,7 @@ void taos_init_imp() {
sprintf
(
temp
,
"%s/taoslog"
,
logDir
);
if
(
taosInitLog
(
temp
,
tsNumOfLogLines
,
10
)
<
0
)
{
printf
(
"failed to open log file
:%s"
,
temp
);
printf
(
"failed to open log file
in directory:%s
\n
"
,
logDir
);
}
tsReadGlobalConfig
();
...
...
src/client/src/tscUtil.c
浏览文件 @
1dcdccb7
...
...
@@ -327,8 +327,8 @@ void tscFreeSqlObj(SSqlObj* pSql) {
}
if
(
pSql
->
fp
==
NULL
)
{
sem_destroy
(
&
pSql
->
rspSem
);
sem_destroy
(
&
pSql
->
emptyRspSem
);
t
sem_destroy
(
&
pSql
->
rspSem
);
t
sem_destroy
(
&
pSql
->
emptyRspSem
);
}
free
(
pSql
);
...
...
src/inc/tmodule.h
浏览文件 @
1dcdccb7
...
...
@@ -22,6 +22,7 @@ extern "C" {
#include <pthread.h>
#include <semaphore.h>
#include "os.h"
typedef
struct
_msg_header
{
int
mid
;
/* message ID */
...
...
@@ -34,8 +35,8 @@ typedef struct _msg_header {
typedef
struct
{
char
*
name
;
/* module name */
pthread_t
thread
;
/* thread ID */
sem_t
emptySem
;
sem_t
fullSem
;
tsem_t
emptySem
;
tsem_t
fullSem
;
int
fullSlot
;
int
emptySlot
;
int
debugFlag
;
...
...
src/inc/ttimer.h
浏览文件 @
1dcdccb7
...
...
@@ -25,6 +25,22 @@ typedef void *tmr_h;
extern
int
tmrDebugFlag
;
extern
int
taosTmrThreads
;
#define tmrError(...) \
if (tmrDebugFlag & DEBUG_ERROR) { \
tprintf("ERROR TMR ", tmrDebugFlag, __VA_ARGS__); \
}
#define tmrWarn(...) \
if (tmrDebugFlag & DEBUG_WARN) { \
tprintf("WARN TMR ", tmrDebugFlag, __VA_ARGS__); \
}
#define tmrTrace(...) \
if (tmrDebugFlag & DEBUG_TRACE) { \
tprintf("TMR ", tmrDebugFlag, __VA_ARGS__); \
}
#define MAX_NUM_OF_TMRCTL 512
#define MSECONDS_PER_TICK 5
void
*
taosTmrInit
(
int
maxTmr
,
int
resoultion
,
int
longest
,
char
*
label
);
tmr_h
taosTmrStart
(
void
(
*
fp
)(
void
*
,
void
*
),
int
mseconds
,
void
*
param1
,
void
*
handle
);
...
...
src/inc/tutil.h
浏览文件 @
1dcdccb7
...
...
@@ -46,22 +46,6 @@ extern "C" {
} \
}
#ifdef WINDOWS
#define taosCloseSocket(fd) closesocket(fd)
#define taosWriteSocket(fd, buf, len) send(fd, buf, len, 0)
#define taosReadSocket(fd, buf, len) recv(fd, buf, len, 0)
#else
#define taosCloseSocket(x) \
{ \
if (VALIDFD(x)) { \
close(x); \
x = -1; \
} \
}
#define taosWriteSocket(fd, buf, len) write(fd, buf, len)
#define taosReadSocket(fd, buf, len) read(fd, buf, len)
#endif
#define tclose(x) taosCloseSocket(x)
#ifdef ASSERTION
...
...
@@ -104,42 +88,6 @@ extern "C" {
#define DEFAULT_UNICODE_ENCODEC "UCS-4LE"
#ifdef LINUX
#define SWAP(a, b, c) \
do { \
typeof(a) __tmp = (a); \
(a) = (b); \
(b) = __tmp; \
} while (0)
#define MAX(a, b) \
({ \
typeof(a) __a = (a); \
typeof(b) __b = (b); \
(__a > __b) ? __a : __b; \
})
#define MIN(a, b) \
({ \
typeof(a) __a = (a); \
typeof(b) __b = (b); \
(__a < __b) ? __a : __b; \
})
#else
#define SWAP(a, b, c) \
do { \
c __tmp = (c)(a); \
(a) = (c)(b); \
(b) = __tmp; \
} while (0)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#define DEFAULT_COMP(x, y) \
do { \
if ((x) == (y)) { \
...
...
@@ -161,12 +109,6 @@ extern "C" {
// align to 8bytes
#define ALIGN8(n) ALIGN_NUM(n, 8)
#ifdef WINDOWS
#define MILLISECOND_PER_SECOND (1000i64)
#else
#define MILLISECOND_PER_SECOND (1000L)
#endif
#define MILLISECOND_PER_MINUTE (MILLISECOND_PER_SECOND * 60)
#define MILLISECOND_PER_HOUR (MILLISECOND_PER_MINUTE * 60)
#define MILLISECOND_PER_DAY (MILLISECOND_PER_HOUR * 24)
...
...
@@ -202,7 +144,7 @@ int64_t str2int64(char *str);
int32_t
taosFileRename
(
char
*
fullPath
,
char
*
suffix
,
char
delimiter
,
char
**
dstPath
);
int32_t
taosInitTimer
(
void
*
(
*
callback
)(
void
*
),
int32_t
ms
);
int32_t
taosInitTimer
(
void
(
*
callback
)(
int
),
int32_t
ms
);
/**
* murmur hash algorithm
...
...
@@ -231,24 +173,6 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, unsigned int inLen, cha
memcpy
(
target
,
context
.
digest
,
TSDB_KEY_LEN
);
}
#ifdef WINDOWS
int32_t
__sync_val_compare_and_swap_32
(
int32_t
*
ptr
,
int32_t
oldval
,
int32_t
newval
);
int32_t
__sync_add_and_fetch_32
(
int32_t
*
ptr
,
int32_t
val
);
int64_t
__sync_val_compare_and_swap_64
(
int64_t
*
ptr
,
int64_t
oldval
,
int64_t
newval
);
int64_t
__sync_add_and_fetch_64
(
int64_t
*
ptr
,
int64_t
val
);
#define twrite write
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
#else
#define __sync_val_compare_and_swap_64 __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_32 __sync_val_compare_and_swap
#define __sync_add_and_fetch_64 __sync_add_and_fetch
#define __sync_add_and_fetch_32 __sync_add_and_fetch
ssize_t
tsendfile
(
int
dfd
,
int
sfd
,
off_t
*
offset
,
size_t
size
);
ssize_t
twrite
(
int
fd
,
void
*
buf
,
size_t
n
);
#endif
#ifdef __cplusplus
}
#endif
...
...
src/kit/shell/CMakeLists.txt
浏览文件 @
1dcdccb7
...
...
@@ -4,12 +4,8 @@ PROJECT(TDengine)
IF
(
TD_LINUX
)
SET
(
SHELL_BUILD_NAME
"ts"
)
SET
(
SHELL_FINAL_NAME
"taos"
)
SET
(
SHELL_CMD_NAME
"taos_cmd"
)
SET
(
SHELL_TARGET_NAME
"taos_target"
)
INCLUDE_DIRECTORIES
(
inc
${
TD_ROOT_DIR
}
/src/inc
${
TD_ROOT_DIR
}
/src/client/inc
${
TD_OS_DIR
}
/inc
)
AUX_SOURCE_DIRECTORY
(
./src SRC
)
LIST
(
REMOVE_ITEM SRC ./src/shellWindows.c
)
...
...
@@ -19,16 +15,29 @@ IF (TD_LINUX)
ELSEIF
(
TD_WINDOWS
)
ADD_DEFINITIONS
(
-DUSE_LIBICONV
)
INCLUDE_DIRECTORIES
(
${
TD_ROOT_DIR
}
/deps/pthread
)
INCLUDE_DIRECTORIES
(
${
TD_ROOT_DIR
}
/deps/regex
)
INCLUDE_DIRECTORIES
(
inc
${
TD_ROOT_DIR
}
/src/inc
${
TD_ROOT_DIR
}
/src/client/inc
${
TD_OS_DIR
}
/inc
)
LIST
(
APPEND SRC ./src/shellEngine.c
)
LIST
(
APPEND SRC ./src/shellMain.c
)
LIST
(
APPEND SRC ./src/shellWindows.c
)
ADD_EXECUTABLE
(
shell
${
SRC
}
)
ADD_EXECUTABLE
(
shell
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
shell taos_static
)
SET_TARGET_PROPERTIES
(
shell PROPERTIES OUTPUT_NAME
"taos"
)
ELSEIF
(
TD_DARWIN
)
INCLUDE_DIRECTORIES
(
inc
${
TD_ROOT_DIR
}
/src/inc
${
TD_ROOT_DIR
}
/src/client/inc
${
TD_OS_DIR
}
/inc
)
LIST
(
APPEND SRC ./src/shellEngine.c
)
LIST
(
APPEND SRC ./src/shellMain.c
)
LIST
(
APPEND SRC ./src/shellWindows.c
)
ADD_EXECUTABLE
(
shell
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
shell taos_static
)
SET_TARGET_PROPERTIES
(
shell PROPERTIES OUTPUT_NAME
"taos"
)
ENDIF
()
src/kit/shell/inc/shellCommand.h
浏览文件 @
1dcdccb7
...
...
@@ -34,7 +34,6 @@ struct Command {
unsigned
endOffset
;
};
extern
void
insertChar
(
Command
*
cmd
,
char
*
c
,
int
size
);
extern
void
backspaceChar
(
Command
*
cmd
);
extern
void
deleteChar
(
Command
*
cmd
);
extern
void
moveCursorLeft
(
Command
*
cmd
);
...
...
src/kit/shell/src/shellEngine.c
浏览文件 @
1dcdccb7
...
...
@@ -34,9 +34,11 @@
/**************** Global variables ****************/
#ifdef WINDOWS
char
CLIENT_VERSION
[]
=
"Welcome to the TDengine shell from windows, client version:%s, "
;
char
CLIENT_VERSION
[]
=
"Welcome to the TDengine shell from windows, client version:%s "
;
#elif defined(DARWIN)
char
CLIENT_VERSION
[]
=
"Welcome to the TDengine shell from mac, client version:%s "
;
#else
char
CLIENT_VERSION
[]
=
"Welcome to the TDengine shell from linux, client version:%s
,
"
;
char
CLIENT_VERSION
[]
=
"Welcome to the TDengine shell from linux, client version:%s "
;
#endif
char
SERVER_VERSION
[]
=
"server version:%s
\n
Copyright (c) 2017 by TAOS Data, Inc. All rights reserved.
\n\n
"
;
char
PROMPT_HEADER
[]
=
"taos> "
;
...
...
@@ -441,10 +443,10 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
printf
(
"%*d|"
,
l
[
i
],
*
((
int
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_BIGINT
:
#ifdef WINDOWS
printf
(
"%*lld|"
,
l
[
i
],
*
((
int64_t
*
)
row
[
i
]));
#else
#ifdef LINUX
printf
(
"%*ld|"
,
l
[
i
],
*
((
int64_t
*
)
row
[
i
]));
#else
printf
(
"%*lld|"
,
l
[
i
],
*
((
int64_t
*
)
row
[
i
]));
#endif
break
;
case
TSDB_DATA_TYPE_FLOAT
:
...
...
@@ -464,10 +466,10 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
if
(
args
.
is_raw_time
)
{
#ifdef WINDOWS
printf
(
" %lld|"
,
*
(
int64_t
*
)
row
[
i
]);
#else
#ifdef LINUX
printf
(
" %ld|"
,
*
(
int64_t
*
)
row
[
i
]);
#else
printf
(
" %lld|"
,
*
(
int64_t
*
)
row
[
i
]);
#endif
}
else
{
if
(
taos_result_precision
(
result
)
==
TSDB_TIME_PRECISION_MICRO
)
{
...
...
@@ -518,10 +520,10 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
printf
(
"%d
\n
"
,
*
((
int
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_BIGINT
:
#ifdef WINDOWS
printf
(
"%lld
\n
"
,
*
((
int64_t
*
)
row
[
i
]));
#else
#ifdef LINUX
printf
(
"%ld
\n
"
,
*
((
int64_t
*
)
row
[
i
]));
#else
printf
(
"%lld
\n
"
,
*
((
int64_t
*
)
row
[
i
]));
#endif
break
;
case
TSDB_DATA_TYPE_FLOAT
:
...
...
@@ -539,10 +541,10 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
if
(
args
.
is_raw_time
)
{
#ifdef WINDOWS
printf
(
"%lld
\n
"
,
*
(
int64_t
*
)
row
[
i
]);
#else
#ifdef LINUX
printf
(
"%ld
\n
"
,
*
(
int64_t
*
)
row
[
i
]);
#else
printf
(
"%lld
\n
"
,
*
(
int64_t
*
)
row
[
i
]);
#endif
}
else
{
if
(
taos_result_precision
(
result
)
==
TSDB_TIME_PRECISION_MICRO
)
{
...
...
@@ -588,10 +590,10 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
fprintf
(
fp
,
"%d"
,
*
((
int
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_BIGINT
:
#ifdef WINDOWS
fprintf
(
fp
,
"%lld"
,
*
((
int64_t
*
)
row
[
i
]));
#else
#ifdef LINUX
fprintf
(
fp
,
"%ld"
,
*
((
int64_t
*
)
row
[
i
]));
#else
fprintf
(
fp
,
"%lld"
,
*
((
int64_t
*
)
row
[
i
]));
#endif
break
;
case
TSDB_DATA_TYPE_FLOAT
:
...
...
@@ -607,10 +609,10 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
fprintf
(
fp
,
"
\'
%s
\'
"
,
t_str
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
#ifdef WINDOWS
fprintf
(
fp
,
"%lld"
,
*
(
int64_t
*
)
row
[
i
]);
#else
#ifdef LINUX
fprintf
(
fp
,
"%ld"
,
*
(
int64_t
*
)
row
[
i
]);
#else
fprintf
(
fp
,
"%lld"
,
*
(
int64_t
*
)
row
[
i
]);
#endif
break
;
default:
...
...
src/kit/shell/src/shellLinux.c
浏览文件 @
1dcdccb7
...
...
@@ -44,6 +44,7 @@
int
indicator
=
1
;
struct
termios
oldtio
;
void
insertChar
(
Command
*
cmd
,
char
*
c
,
int
size
);
const
char
*
argp_program_version
=
version
;
const
char
*
argp_program_bug_address
=
"<support@taosdata.com>"
;
static
char
doc
[]
=
""
;
...
...
src/kit/shell/src/shellMain.c
浏览文件 @
1dcdccb7
...
...
@@ -31,6 +31,7 @@ int32_t TIMESTAMP_OUTPUT_LENGTH = 22;
// TODO: IMPLEMENT INTERRUPT HANDLER.
void
interruptHandler
(
int
signum
)
{
#ifdef LINUX
TAOS_RES
*
res
=
taos_use_result
(
con
);
taos_stop_query
(
res
);
if
(
res
!=
NULL
)
{
...
...
@@ -41,6 +42,10 @@ void interruptHandler(int signum) {
tscQueueAsyncFreeResult
(
res
);
}
result
=
NULL
;
#else
printf
(
"
\n
Receive ctrl+c or other signal, quit shell.
\n
"
);
exit
(
0
);
#endif
}
int
checkVersion
()
{
...
...
src/os/CMakeLists.txt
浏览文件 @
1dcdccb7
...
...
@@ -4,3 +4,4 @@ PROJECT(TDengine)
ADD_SUBDIRECTORY
(
linux
)
ADD_SUBDIRECTORY
(
windows
)
ADD_SUBDIRECTORY
(
darwin
)
src/os/darwin/CMakeLists.txt
0 → 100644
浏览文件 @
1dcdccb7
CMAKE_MINIMUM_REQUIRED
(
VERSION 2.8
)
PROJECT
(
TDengine
)
IF
(
TD_DARWIN
)
AUX_SOURCE_DIRECTORY
(
src SRC
)
INCLUDE_DIRECTORIES
(
inc
${
TD_ROOT_DIR
}
/src/inc
)
ADD_LIBRARY
(
os
${
SRC
}
)
ENDIF
()
src/os/darwin/inc/os.h
0 → 100644
浏览文件 @
1dcdccb7
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_PLATFORM_DARWIN_H
#define TDENGINE_PLATFORM_DARWIN_H
#include <ifaddrs.h>
#include <netdb.h>
#include <pwd.h>
#include <syslog.h>
#include <termios.h>
#include <wordexp.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <sys/un.h>
#include <stdint.h>
#include <pthread.h>
#include <stdbool.h>
#include <limits.h>
#include <locale.h>
#include <dispatch/dispatch.h>
#define htobe64 htonll
#define taosCloseSocket(x) \
{ \
if (VALIDFD(x)) { \
close(x); \
x = -1; \
} \
}
#define taosWriteSocket(fd, buf, len) write(fd, buf, len)
#define taosReadSocket(fd, buf, len) read(fd, buf, len)
#define __sync_val_compare_and_swap_64 __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_32 __sync_val_compare_and_swap
#define __sync_add_and_fetch_64 __sync_add_and_fetch
#define __sync_add_and_fetch_32 __sync_add_and_fetch
#define SWAP(a, b, c) \
do { \
typeof(a) __tmp = (a); \
(a) = (b); \
(b) = __tmp; \
} while (0)
#define MAX(a, b) \
({ \
typeof(a) __a = (a); \
typeof(b) __b = (b); \
(__a > __b) ? __a : __b; \
})
#define MIN(a, b) \
({ \
typeof(a) __a = (a); \
typeof(b) __b = (b); \
(__a < __b) ? __a : __b; \
})
#define MILLISECOND_PER_SECOND (1000L)
#define tsem_t dispatch_semaphore_t
int
tsem_init
(
dispatch_semaphore_t
*
sem
,
int
pshared
,
unsigned
int
value
);
int
tsem_wait
(
dispatch_semaphore_t
*
sem
);
int
tsem_post
(
dispatch_semaphore_t
*
sem
);
int
tsem_destroy
(
dispatch_semaphore_t
*
sem
);
ssize_t
twrite
(
int
fd
,
void
*
buf
,
size_t
n
);
char
*
taosCharsetReplace
(
char
*
charsetstr
);
bool
taosCheckPthreadValid
(
pthread_t
thread
);
void
taosResetPthread
(
pthread_t
*
thread
);
int64_t
taosGetPthreadId
();
int
taosSetNonblocking
(
int
sock
,
int
on
);
int
taosSetSockOpt
(
int
socketfd
,
int
level
,
int
optname
,
void
*
optval
,
int
optlen
);
void
tsPrintOsInfo
();
char
*
taosCharsetReplace
(
char
*
charsetstr
);
void
tsPrintOsInfo
();
void
taosGetSystemInfo
();
void
taosKillSystem
();
bool
taosSkipSocketCheck
();
bool
taosGetDisk
();
typedef
int
(
*
__compar_fn_t
)(
const
void
*
,
const
void
*
);
// for send function in tsocket.c
#define MSG_NOSIGNAL 0
#define SO_NO_CHECK 0x1234
#define SOL_TCP 0x1234
#define TCP_KEEPIDLE 0x1234
#ifndef PTHREAD_MUTEX_RECURSIVE_NP
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
#endif
#endif
\ No newline at end of file
src/os/darwin/src/tdarwin.c
0 → 100644
浏览文件 @
1dcdccb7
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <fcntl.h>
#include <ifaddrs.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>
#include <unistd.h>
#include <sys/utsname.h>
#include "tglobalcfg.h"
#include "tlog.h"
#include "tsdb.h"
#include "tutil.h"
char
configDir
[
TSDB_FILENAME_LEN
]
=
"~/TDengine/cfg"
;
char
tsDirectory
[
TSDB_FILENAME_LEN
]
=
"~/TDengine/data"
;
char
dataDir
[
TSDB_FILENAME_LEN
]
=
"~/TDengine/data"
;
char
logDir
[
TSDB_FILENAME_LEN
]
=
"~/TDengine/log"
;
char
scriptDir
[
TSDB_FILENAME_LEN
]
=
"~/TDengine/script"
;
int64_t
str2int64
(
char
*
str
)
{
char
*
endptr
=
NULL
;
return
strtoll
(
str
,
&
endptr
,
10
);
}
/*
to make taosMsleep work,
signal SIGALRM shall be blocked in the calling thread,
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGALRM);
pthread_sigmask(SIG_BLOCK, &set, NULL);
*/
void
taosMsleep
(
int
mseconds
)
{
struct
timeval
timeout
;
int
seconds
,
useconds
;
seconds
=
mseconds
/
1000
;
useconds
=
(
mseconds
%
1000
)
*
1000
;
timeout
.
tv_sec
=
seconds
;
timeout
.
tv_usec
=
useconds
;
/* sigset_t set; */
/* sigemptyset(&set); */
/* sigaddset(&set, SIGALRM); */
/* pthread_sigmask(SIG_BLOCK, &set, NULL); */
select
(
0
,
NULL
,
NULL
,
NULL
,
&
timeout
);
/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */
}
bool
taosCheckPthreadValid
(
pthread_t
thread
)
{
return
thread
!=
0
;
}
void
taosResetPthread
(
pthread_t
*
thread
)
{
*
thread
=
0
;
}
int64_t
taosGetPthreadId
()
{
return
(
int64_t
)
pthread_self
();
}
/*
* Function to get the private ip address of current machine. If get IP
* successfully, return 0, else, return -1. The return values is ip.
*
* Use:
* if (taosGetPrivateIp(ip) != 0) {
* perror("Fail to get private IP address\n");
* exit(EXIT_FAILURE);
* }
*/
int
taosGetPrivateIp
(
char
*
const
ip
)
{
bool
hasLoCard
=
false
;
struct
ifaddrs
*
ifaddr
,
*
ifa
;
int
family
,
s
;
char
host
[
NI_MAXHOST
];
if
(
getifaddrs
(
&
ifaddr
)
==
-
1
)
{
return
-
1
;
}
/* Walk through linked list, maintaining head pointer so we can free list later */
int
flag
=
0
;
for
(
ifa
=
ifaddr
;
ifa
!=
NULL
;
ifa
=
ifa
->
ifa_next
)
{
if
(
ifa
->
ifa_addr
==
NULL
)
continue
;
family
=
ifa
->
ifa_addr
->
sa_family
;
if
(
strcmp
(
"lo"
,
ifa
->
ifa_name
)
==
0
)
{
hasLoCard
=
true
;
continue
;
}
if
(
family
==
AF_INET
)
{
/* printf("%-8s", ifa->ifa_name); */
s
=
getnameinfo
(
ifa
->
ifa_addr
,
(
family
==
AF_INET
)
?
sizeof
(
struct
sockaddr_in
)
:
sizeof
(
struct
sockaddr_in6
),
host
,
NI_MAXHOST
,
NULL
,
0
,
NI_NUMERICHOST
);
if
(
s
!=
0
)
{
freeifaddrs
(
ifaddr
);
return
-
1
;
}
strcpy
(
ip
,
host
);
flag
=
1
;
break
;
}
}
freeifaddrs
(
ifaddr
);
if
(
flag
)
{
return
0
;
}
else
{
if
(
hasLoCard
)
{
pPrint
(
"no net card was found, use lo:127.0.0.1 as default"
);
strcpy
(
ip
,
"127.0.0.1"
);
return
0
;
}
return
-
1
;
}
}
int
taosSetNonblocking
(
int
sock
,
int
on
)
{
int
flags
=
0
;
if
((
flags
=
fcntl
(
sock
,
F_GETFL
,
0
))
<
0
)
{
pError
(
"fcntl(F_GETFL) error: %d (%s)
\n
"
,
errno
,
strerror
(
errno
));
return
1
;
}
if
(
on
)
flags
|=
O_NONBLOCK
;
else
flags
&=
~
O_NONBLOCK
;
if
((
flags
=
fcntl
(
sock
,
F_SETFL
,
flags
))
<
0
)
{
pError
(
"fcntl(F_SETFL) error: %d (%s)
\n
"
,
errno
,
strerror
(
errno
));
return
1
;
}
return
0
;
}
int
taosSetSockOpt
(
int
socketfd
,
int
level
,
int
optname
,
void
*
optval
,
int
optlen
)
{
if
(
level
==
SOL_SOCKET
&&
optname
==
SO_SNDBUF
)
{
return
0
;
}
if
(
level
==
SOL_SOCKET
&&
optname
==
SO_RCVBUF
)
{
return
0
;
}
return
setsockopt
(
socketfd
,
level
,
optname
,
optval
,
(
socklen_t
)
optlen
);
}
int
taosOpenUDClientSocket
(
char
*
ip
,
short
port
)
{
int
sockFd
=
0
;
struct
sockaddr_un
serverAddr
;
int
ret
;
char
name
[
128
];
sprintf
(
name
,
"%s.%d"
,
ip
,
port
);
sockFd
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
0
);
if
(
sockFd
<
0
)
{
pError
(
"failed to open the UD socket:%s, reason:%s"
,
name
,
strerror
(
errno
));
return
-
1
;
}
memset
((
char
*
)
&
serverAddr
,
0
,
sizeof
(
serverAddr
));
serverAddr
.
sun_family
=
AF_UNIX
;
strcpy
(
serverAddr
.
sun_path
+
1
,
name
);
ret
=
connect
(
sockFd
,
(
struct
sockaddr
*
)
&
serverAddr
,
sizeof
(
serverAddr
));
if
(
ret
!=
0
)
{
pError
(
"failed to connect UD socket, name:%d, reason: %s"
,
name
,
strerror
(
errno
));
sockFd
=
-
1
;
}
return
sockFd
;
}
int
taosOpenUDServerSocket
(
char
*
ip
,
short
port
)
{
struct
sockaddr_un
serverAdd
;
int
sockFd
;
char
name
[
128
];
pTrace
(
"open ud socket:%s"
,
name
);
// if (tsAllowLocalhost) ip = "0.0.0.0";
sprintf
(
name
,
"%s.%d"
,
ip
,
port
);
bzero
((
char
*
)
&
serverAdd
,
sizeof
(
serverAdd
));
serverAdd
.
sun_family
=
AF_UNIX
;
strcpy
(
serverAdd
.
sun_path
+
1
,
name
);
unlink
(
name
);
if
((
sockFd
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
0
))
<
0
)
{
pError
(
"failed to open UD socket:%s, reason:%s"
,
name
,
strerror
(
errno
));
return
-
1
;
}
/* bind socket to server address */
if
(
bind
(
sockFd
,
(
struct
sockaddr
*
)
&
serverAdd
,
sizeof
(
serverAdd
))
<
0
)
{
pError
(
"bind socket:%s failed, reason:%s"
,
name
,
strerror
(
errno
));
tclose
(
sockFd
);
return
-
1
;
}
if
(
listen
(
sockFd
,
10
)
<
0
)
{
pError
(
"listen socket:%s failed, reason:%s"
,
name
,
strerror
(
errno
));
return
-
1
;
}
return
sockFd
;
}
int
taosInitTimer
(
void
(
*
callback
)(
int
),
int
ms
)
{
signal
(
SIGALRM
,
callback
);
struct
itimerval
tv
;
tv
.
it_interval
.
tv_sec
=
0
;
/* my timer resolution */
tv
.
it_interval
.
tv_usec
=
1000
*
ms
;
// resolution is in msecond
tv
.
it_value
=
tv
.
it_interval
;
return
setitimer
(
ITIMER_REAL
,
&
tv
,
NULL
);
}
char
*
taosCharsetReplace
(
char
*
charsetstr
)
{
return
charsetstr
;
}
void
taosGetSystemTimezone
()
{
// get and set default timezone
SGlobalConfig
*
cfg_timezone
=
tsGetConfigOption
(
"timezone"
);
if
(
cfg_timezone
&&
cfg_timezone
->
cfgStatus
<
TSDB_CFG_CSTATUS_DEFAULT
)
{
char
*
tz
=
getenv
(
"TZ"
);
if
(
tz
==
NULL
||
strlen
(
tz
)
==
0
)
{
strcpy
(
tsTimezone
,
"not configured"
);
}
else
{
strcpy
(
tsTimezone
,
tz
);
}
cfg_timezone
->
cfgStatus
=
TSDB_CFG_CSTATUS_DEFAULT
;
pPrint
(
"timezone not configured, use default"
);
}
}
void
taosGetSystemLocale
()
{
// get and set default locale
SGlobalConfig
*
cfg_locale
=
tsGetConfigOption
(
"locale"
);
if
(
cfg_locale
&&
cfg_locale
->
cfgStatus
<
TSDB_CFG_CSTATUS_DEFAULT
)
{
char
*
locale
=
setlocale
(
LC_CTYPE
,
"chs"
);
if
(
locale
!=
NULL
)
{
strncpy
(
tsLocale
,
locale
,
sizeof
(
tsLocale
)
/
sizeof
(
tsLocale
[
0
]));
cfg_locale
->
cfgStatus
=
TSDB_CFG_CSTATUS_DEFAULT
;
pPrint
(
"locale not configured, set to default:%s"
,
tsLocale
);
}
}
SGlobalConfig
*
cfg_charset
=
tsGetConfigOption
(
"charset"
);
if
(
cfg_charset
&&
cfg_charset
->
cfgStatus
<
TSDB_CFG_CSTATUS_DEFAULT
)
{
strcpy
(
tsCharset
,
"cp936"
);
cfg_charset
->
cfgStatus
=
TSDB_CFG_CSTATUS_DEFAULT
;
pPrint
(
"charset not configured, set to default:%s"
,
tsCharset
);
}
}
void
tsPrintOsInfo
()
{}
void
taosKillSystem
()
{
tError
(
"function taosKillSystem, exit!"
);
exit
(
0
);
}
bool
taosGetDisk
()
{
return
true
;
}
void
taosGetSystemInfo
()
{
taosGetSystemTimezone
();
taosGetSystemLocale
();
}
void
*
taosInitTcpClient
(
char
*
ip
,
short
port
,
char
*
flabel
,
int
num
,
void
*
fp
,
void
*
shandle
)
{
tError
(
"function taosInitTcpClient is not implemented in darwin system, exit!"
);
exit
(
0
);
}
void
taosCloseTcpClientConnection
(
void
*
chandle
)
{
tError
(
"function taosCloseTcpClientConnection is not implemented in darwin system, exit!"
);
exit
(
0
);
}
void
*
taosOpenTcpClientConnection
(
void
*
shandle
,
void
*
thandle
,
char
*
ip
,
short
port
)
{
tError
(
"function taosOpenTcpClientConnection is not implemented in darwin system, exit!"
);
exit
(
0
);
}
int
taosSendTcpClientData
(
unsigned
int
ip
,
short
port
,
char
*
data
,
int
len
,
void
*
chandle
)
{
tError
(
"function taosSendTcpClientData is not implemented in darwin system, exit!"
);
exit
(
0
);
}
void
taosCleanUpTcpClient
(
void
*
chandle
)
{
tError
(
"function taosCleanUpTcpClient is not implemented in darwin system, exit!"
);
exit
(
0
);
}
void
taosCloseTcpServerConnection
(
void
*
chandle
)
{
tError
(
"function taosCloseTcpServerConnection is not implemented in darwin system, exit!"
);
exit
(
0
);
}
void
taosCleanUpTcpServer
(
void
*
handle
)
{
tError
(
"function taosCleanUpTcpServer is not implemented in darwin system, exit!"
);
exit
(
0
);
}
void
*
taosInitTcpServer
(
char
*
ip
,
short
port
,
char
*
label
,
int
numOfThreads
,
void
*
fp
,
void
*
shandle
)
{
tError
(
"function taosInitTcpServer is not implemented in darwin system, exit!"
);
exit
(
0
);
}
int
taosSendTcpServerData
(
unsigned
int
ip
,
short
port
,
char
*
data
,
int
len
,
void
*
chandle
)
{
tError
(
"function taosSendTcpServerData is not implemented in darwin system, exit!"
);
exit
(
0
);
}
void
taosFreeMsgHdr
(
void
*
hdr
)
{
tError
(
"function taosFreeMsgHdr is not implemented in darwin system, exit!"
);
exit
(
0
);
}
int
taosMsgHdrSize
(
void
*
hdr
)
{
tError
(
"function taosMsgHdrSize is not implemented in darwin system, exit!"
);
exit
(
0
);
}
void
taosSendMsgHdr
(
void
*
hdr
,
int
fd
)
{
tError
(
"function taosSendMsgHdr is not implemented in darwin system, exit!"
);
exit
(
0
);
}
void
taosInitMsgHdr
(
void
**
hdr
,
void
*
dest
,
int
maxPkts
)
{
tError
(
"function taosInitMsgHdr is not implemented in darwin system, exit!"
);
exit
(
0
);
}
void
taosSetMsgHdrData
(
void
*
hdr
,
char
*
data
,
int
dataLen
)
{
tError
(
"function taosSetMsgHdrData is not implemented in darwin system, exit!"
);
exit
(
0
);
}
ssize_t
twrite
(
int
fd
,
void
*
buf
,
size_t
n
)
{
size_t
nleft
=
n
;
ssize_t
nwritten
=
0
;
char
*
tbuf
=
(
char
*
)
buf
;
while
(
nleft
>
0
)
{
nwritten
=
write
(
fd
,
(
void
*
)
tbuf
,
nleft
);
if
(
nwritten
<
0
)
{
if
(
errno
==
EINTR
)
{
continue
;
}
return
-
1
;
}
nleft
-=
nwritten
;
tbuf
+=
nwritten
;
}
return
n
;
}
bool
taosSkipSocketCheck
()
{
return
true
;
}
int
tsem_init
(
dispatch_semaphore_t
*
sem
,
int
pshared
,
unsigned
int
value
)
{
*
sem
=
dispatch_semaphore_create
(
value
);
if
(
*
sem
==
NULL
)
{
return
-
1
;
}
else
{
return
0
;
}
}
int
tsem_wait
(
dispatch_semaphore_t
*
sem
)
{
dispatch_semaphore_wait
(
*
sem
,
DISPATCH_TIME_FOREVER
);
return
0
;
}
int
tsem_post
(
dispatch_semaphore_t
*
sem
)
{
dispatch_semaphore_signal
(
*
sem
);
return
0
;
}
int
tsem_destroy
(
dispatch_semaphore_t
*
sem
)
{
return
0
;
}
\ No newline at end of file
src/os/linux/inc/os.h
浏览文件 @
1dcdccb7
...
...
@@ -45,6 +45,54 @@
#include <limits.h>
#include <sys/sendfile.h>
#define taosCloseSocket(x) \
{ \
if (VALIDFD(x)) { \
close(x); \
x = -1; \
} \
}
#define taosWriteSocket(fd, buf, len) write(fd, buf, len)
#define taosReadSocket(fd, buf, len) read(fd, buf, len)
#define __sync_val_compare_and_swap_64 __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_32 __sync_val_compare_and_swap
#define __sync_add_and_fetch_64 __sync_add_and_fetch
#define __sync_add_and_fetch_32 __sync_add_and_fetch
#define SWAP(a, b, c) \
do { \
typeof(a) __tmp = (a); \
(a) = (b); \
(b) = __tmp; \
} while (0)
#define MAX(a, b) \
({ \
typeof(a) __a = (a); \
typeof(b) __b = (b); \
(__a > __b) ? __a : __b; \
})
#define MIN(a, b) \
({ \
typeof(a) __a = (a); \
typeof(b) __b = (b); \
(__a < __b) ? __a : __b; \
})
#define MILLISECOND_PER_SECOND (1000L)
#define tsem_t sem_t
#define tsem_init sem_init
#define tsem_wait sem_wait
#define tsem_post sem_post
#define tsem_destroy sem_destroy
ssize_t
tsendfile
(
int
dfd
,
int
sfd
,
off_t
*
offset
,
size_t
size
);
ssize_t
twrite
(
int
fd
,
void
*
buf
,
size_t
n
);
bool
taosCheckPthreadValid
(
pthread_t
thread
);
void
taosResetPthread
(
pthread_t
*
thread
);
...
...
@@ -63,6 +111,6 @@ void taosGetSystemInfo();
void
taosKillSystem
();
bool
taos
IsRunningWSLv1
();
bool
taos
SkipSocketCheck
();
#endif
\ No newline at end of file
src/os/linux/src/
os
.c
→
src/os/linux/src/
tlinux
.c
浏览文件 @
1dcdccb7
...
...
@@ -32,6 +32,7 @@
#include "tlog.h"
#include "tsdb.h"
#include "tutil.h"
#include "ttimer.h"
char
configDir
[
TSDB_FILENAME_LEN
]
=
"/etc/taos"
;
char
tsDirectory
[
TSDB_FILENAME_LEN
]
=
"/var/lib/taos"
;
...
...
@@ -224,32 +225,61 @@ int taosOpenUDServerSocket(char *ip, short port) {
return
sockFd
;
}
// The callback functions MUST free the param pass to it after finishing use it.
int
taosInitTimer
(
void
*
(
*
callback
)(
void
*
),
int
ms
)
{
/********************************************************
* Create SIGALRM loop thread
********************************************************/
pthread_t
thread
;
pthread_attr_t
tattr
;
if
(
pthread_attr_init
(
&
tattr
))
{
return
-
1
;
void
*
taosProcessAlarmSignal
(
void
*
tharg
)
{
// Block the signal
sigset_t
sigset
;
sigemptyset
(
&
sigset
);
sigaddset
(
&
sigset
,
SIGALRM
);
sigprocmask
(
SIG_BLOCK
,
&
sigset
,
NULL
);
void
(
*
callback
)(
int
)
=
tharg
;
timer_t
timerId
;
struct
sigevent
sevent
;
sevent
.
sigev_notify
=
SIGEV_THREAD_ID
;
sevent
.
_sigev_un
.
_tid
=
syscall
(
__NR_gettid
);
sevent
.
sigev_signo
=
SIGALRM
;
if
(
timer_create
(
CLOCK_REALTIME
,
&
sevent
,
&
timerId
)
==
-
1
)
{
tmrError
(
"Failed to create timer"
);
}
if
(
pthread_attr_setdetachstate
(
&
tattr
,
PTHREAD_CREATE_DETACHED
))
{
return
-
1
;
struct
itimerspec
ts
;
ts
.
it_value
.
tv_sec
=
0
;
ts
.
it_value
.
tv_nsec
=
1000000
*
MSECONDS_PER_TICK
;
ts
.
it_interval
.
tv_sec
=
0
;
ts
.
it_interval
.
tv_nsec
=
1000000
*
MSECONDS_PER_TICK
;
if
(
timer_settime
(
timerId
,
0
,
&
ts
,
NULL
))
{
tmrError
(
"Failed to init timer"
);
return
NULL
;
}
int
*
tms
=
(
int
*
)
malloc
(
sizeof
(
int
));
*
tms
=
ms
;
if
(
pthread_create
(
&
thread
,
&
tattr
,
callback
,
(
void
*
)
tms
))
{
free
(
tms
);
return
-
1
;
int
signo
;
while
(
1
)
{
if
(
sigwait
(
&
sigset
,
&
signo
))
{
tmrError
(
"Failed to wait signal: number %d"
,
signo
);
continue
;
}
/* printf("Signal handling: number %d ......\n", signo); */
callback
(
0
);
}
if
(
pthread_attr_destroy
(
&
tattr
))
{
return
-
1
;
assert
(
0
);
return
NULL
;
}
int
taosInitTimer
(
void
(
*
callback
)(
int
),
int
ms
)
{
pthread_t
thread
;
pthread_attr_t
tattr
;
pthread_attr_init
(
&
tattr
);
pthread_attr_setdetachstate
(
&
tattr
,
PTHREAD_CREATE_DETACHED
);
if
(
pthread_create
(
&
thread
,
&
tattr
,
taosProcessAlarmSignal
,
callback
)
!=
0
)
{
tmrError
(
"failed to create timer thread"
);
return
-
1
;
}
pthread_attr_destroy
(
&
tattr
);
return
0
;
}
...
...
@@ -296,16 +326,15 @@ ssize_t twrite(int fd, void *buf, size_t n) {
return
n
;
}
// check if the linux running is WSL
bool
taosIsRunningWSLv1
()
{
bool
taosSkipSocketCheck
()
{
struct
utsname
buf
;
if
(
uname
(
&
buf
))
{
pPrint
(
"
can't fetch os info"
);
pPrint
(
"can't fetch os info"
);
return
false
;
}
if
(
strstr
(
buf
.
release
,
"Microsoft"
)
!=
0
)
{
pPrint
(
"
using WSLv1"
);
pPrint
(
"using WSLv1"
);
return
true
;
}
...
...
src/
util
/src/tsystem.c
→
src/
os/linux
/src/tsystem.c
浏览文件 @
1dcdccb7
文件已移动
src/os/windows/inc/os.h
浏览文件 @
1dcdccb7
...
...
@@ -64,6 +64,38 @@ extern "C" {
#define in_addr_t unsigned long
#define socklen_t int
#define htobe64 htonll
#define twrite write
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
#define taosCloseSocket(fd) closesocket(fd)
#define taosWriteSocket(fd, buf, len) send(fd, buf, len, 0)
#define taosReadSocket(fd, buf, len) recv(fd, buf, len, 0)
int32_t
__sync_val_compare_and_swap_32
(
int32_t
*
ptr
,
int32_t
oldval
,
int32_t
newval
);
int32_t
__sync_add_and_fetch_32
(
int32_t
*
ptr
,
int32_t
val
);
int64_t
__sync_val_compare_and_swap_64
(
int64_t
*
ptr
,
int64_t
oldval
,
int64_t
newval
);
int64_t
__sync_add_and_fetch_64
(
int64_t
*
ptr
,
int64_t
val
);
#define SWAP(a, b, c) \
do { \
c __tmp = (c)(a); \
(a) = (c)(b); \
(b) = __tmp; \
} while (0)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MILLISECOND_PER_SECOND (1000i64)
#define tsem_t sem_t
#define tsem_init sem_init
#define tsem_wait sem_wait
#define tsem_post sem_post
#define tsem_destroy sem_destroy
int
getline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
);
...
...
@@ -124,7 +156,7 @@ int sigaction(int, struct sigaction *, void *);
void
sleep
(
int
mseconds
);
bool
taos
IsRunningWSLv1
();
bool
taos
SkipSocketCheck
();
#ifdef __cplusplus
}
...
...
src/os/windows/src/twindows.c
浏览文件 @
1dcdccb7
...
...
@@ -47,10 +47,6 @@ int64_t taosGetPthreadId() {
}
int
taosSetSockOpt
(
int
socketfd
,
int
level
,
int
optname
,
void
*
optval
,
int
optlen
)
{
if
(
level
==
SOL_SOCKET
&&
optname
==
SO_NO_CHECK
)
{
return
0
;
}
if
(
level
==
SOL_TCP
&&
optname
==
TCP_KEEPCNT
)
{
return
0
;
}
...
...
@@ -195,8 +191,10 @@ int wordexp(const char *words, wordexp_t *pwordexp, int flags) {
}
void
wordfree
(
wordexp_t
*
pwordexp
)
{}
void
taosGetDisk
()
{}
bool
taosIsRunningWSLv1
()
{
bool
taosSkipSocketCheck
()
{
return
false
;
}
src/os/windows/src/twintimer.c
浏览文件 @
1dcdccb7
...
...
@@ -20,7 +20,7 @@
#pragma warning( disable : 4244 )
typedef
void
(
*
win_timer_f
)(
int
signo
);
typedef
void
(
*
win_timer_f
)(
int
signo
);
void
WINAPI
taosWinOnTimer
(
UINT
wTimerID
,
UINT
msg
,
DWORD_PTR
dwUser
,
DWORD_PTR
dwl
,
DWORD_PTR
dw2
)
{
...
...
src/rpc/CMakeLists.txt
浏览文件 @
1dcdccb7
...
...
@@ -6,6 +6,11 @@ INCLUDE_DIRECTORIES(inc ${TD_ROOT_DIR}/src/inc ${TD_OS_DIR}/inc)
IF
(
TD_LINUX
)
AUX_SOURCE_DIRECTORY
(
./src SRC
)
ELSEIF
(
TD_DARWIN
)
LIST
(
APPEND SRC ./src/thaship.c
)
LIST
(
APPEND SRC ./src/trpc.c
)
LIST
(
APPEND SRC ./src/tstring.c
)
LIST
(
APPEND SRC ./src/tudp.c
)
ELSEIF
(
TD_WINDOWS
)
INCLUDE_DIRECTORIES
(
${
TD_ROOT_DIR
}
/deps/pthread
)
LIST
(
APPEND SRC ./src/thaship.c
)
...
...
src/util/CMakeLists.txt
浏览文件 @
1dcdccb7
...
...
@@ -61,5 +61,41 @@ ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
LIST
(
APPEND SRC ./src/version.c
)
ADD_LIBRARY
(
tutil
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
tutil iconv regex pthread os winmm IPHLPAPI ws2_32
)
ELSEIF
(
TD_DARWIN
)
ADD_DEFINITIONS
(
-DUSE_LIBICONV
)
INCLUDE_DIRECTORIES
(
${
TD_ROOT_DIR
}
/src/inc
)
INCLUDE_DIRECTORIES
(
${
TD_OS_DIR
}
/inc
)
LIST
(
APPEND SRC ./src/ihash.c
)
LIST
(
APPEND SRC ./src/shash.c
)
LIST
(
APPEND SRC ./src/sql.c
)
LIST
(
APPEND SRC ./src/tbase64.c
)
LIST
(
APPEND SRC ./src/tcache.c
)
LIST
(
APPEND SRC ./src/textbuffer.c
)
LIST
(
APPEND SRC ./src/tglobalcfg.c
)
LIST
(
APPEND SRC ./src/thash.c
)
LIST
(
APPEND SRC ./src/thashutil.c
)
LIST
(
APPEND SRC ./src/thistogram.c
)
LIST
(
APPEND SRC ./src/tidpool.c
)
LIST
(
APPEND SRC ./src/tinterpolation.c
)
LIST
(
APPEND SRC ./src/tlog.c
)
LIST
(
APPEND SRC ./src/tlosertree.c
)
LIST
(
APPEND SRC ./src/tmd5.c
)
LIST
(
APPEND SRC ./src/tmempool.c
)
LIST
(
APPEND SRC ./src/tmodule.c
)
LIST
(
APPEND SRC ./src/tsched.c
)
LIST
(
APPEND SRC ./src/tskiplist.c
)
LIST
(
APPEND SRC ./src/tsocket.c
)
LIST
(
APPEND SRC ./src/tstatus.c
)
LIST
(
APPEND SRC ./src/tstoken.c
)
LIST
(
APPEND SRC ./src/ttime.c
)
LIST
(
APPEND SRC ./src/ttimer.c
)
LIST
(
APPEND SRC ./src/ttokenizer.c
)
LIST
(
APPEND SRC ./src/ttypes.c
)
LIST
(
APPEND SRC ./src/tutil.c
)
LIST
(
APPEND SRC ./src/version.c
)
ADD_LIBRARY
(
tutil
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
tutil iconv pthread os
)
ENDIF
()
src/util/src/tglobalcfg.c
浏览文件 @
1dcdccb7
...
...
@@ -615,11 +615,11 @@ void tsReadGlobalLogConfig() {
}
wordfree
(
&
full_path
);
tsReadLogOption
(
"logDir"
,
logDir
);
sprintf
(
fileName
,
"%s/taos.cfg"
,
configDir
);
fp
=
fopen
(
fileName
,
"r"
);
if
(
fp
==
NULL
)
{
printf
(
"option file:%s not found, all options are set to system default
\n
"
,
fileName
);
tsReadLogOption
(
"logDir"
,
logDir
);
printf
(
"
\n
option file:%s not found, all options are set to system default
\n
"
,
fileName
);
return
;
}
...
...
src/util/src/thistogram.c
浏览文件 @
1dcdccb7
...
...
@@ -453,7 +453,7 @@ void tHistogramPrint(SHistogramInfo* pHisto) {
printf
(
"total entries: %d, elements: %d
\n
"
,
pHisto
->
numOfEntries
,
pHisto
->
numOfElems
);
#if defined(USE_ARRAYLIST)
for
(
int32_t
i
=
0
;
i
<
pHisto
->
numOfEntries
;
++
i
)
{
printf
(
"%d: (%f, %ld)
\n
"
,
i
+
1
,
pHisto
->
elems
[
i
].
val
,
pHisto
->
elems
[
i
].
num
);
printf
(
"%d: (%f, %l
l
d)
\n
"
,
i
+
1
,
pHisto
->
elems
[
i
].
val
,
pHisto
->
elems
[
i
].
num
);
}
#else
tSkipListNode
*
pNode
=
pHisto
->
pList
->
pHead
.
pForward
[
0
];
...
...
src/util/src/tlog.c
浏览文件 @
1dcdccb7
...
...
@@ -55,7 +55,7 @@ typedef struct {
int
stop
;
pthread_t
asyncThread
;
pthread_mutex_t
buffMutex
;
sem_t
buffNotEmpty
;
t
sem_t
buffNotEmpty
;
}
SLogBuff
;
int
uDebugFlag
=
131
;
// all the messages
...
...
@@ -113,7 +113,7 @@ void taosStopLog() {
void
taosCloseLogger
()
{
taosStopLog
();
sem_post
(
&
(
logHandle
->
buffNotEmpty
));
t
sem_post
(
&
(
logHandle
->
buffNotEmpty
));
if
(
taosCheckPthreadValid
(
logHandle
->
asyncThread
))
{
pthread_join
(
logHandle
->
asyncThread
,
NULL
);
}
...
...
@@ -211,7 +211,7 @@ bool taosCheckFileIsOpen(char *logFileName) {
int
fd
=
open
(
logFileName
,
O_WRONLY
|
O_CREAT
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
if
(
fd
<
0
)
{
printf
(
"failed to open log file:%s, reason:%s
\n
"
,
logFileName
,
strerror
(
errno
));
printf
(
"
\n
failed to open log file:%s, reason:%s
\n
"
,
logFileName
,
strerror
(
errno
));
return
true
;
}
...
...
@@ -286,7 +286,7 @@ int taosOpenLogFileWithMaxLines(char *fn, int maxLines, int maxFileNum) {
logHandle
->
fd
=
open
(
name
,
O_WRONLY
|
O_CREAT
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
if
(
logHandle
->
fd
<
0
)
{
printf
(
"failed to open log file:%s, reason:%s
\n
"
,
name
,
strerror
(
errno
));
printf
(
"
\n
failed to open log file:%s, reason:%s
\n
"
,
name
,
strerror
(
errno
));
return
-
1
;
}
taosLockFile
(
logHandle
->
fd
);
...
...
@@ -318,7 +318,7 @@ char *tprefix(char *prefix) {
curTime
=
timeSecs
.
tv_sec
;
ptm
=
localtime_r
(
&
curTime
,
&
Tm
);
#if
def WINDOWS
#if
ndef LINUX
sprintf
(
prefix
,
"%02d/%02d %02d:%02d:%02d.%06d 0x%lld "
,
ptm
->
tm_mon
+
1
,
ptm
->
tm_mday
,
ptm
->
tm_hour
,
ptm
->
tm_min
,
ptm
->
tm_sec
,
(
int
)
timeSecs
.
tv_usec
,
taosGetPthreadId
());
#else
...
...
@@ -345,7 +345,7 @@ void tprintf(const char *const flags, int dflag, const char *const format, ...)
gettimeofday
(
&
timeSecs
,
NULL
);
curTime
=
timeSecs
.
tv_sec
;
ptm
=
localtime_r
(
&
curTime
,
&
Tm
);
#if
def WINDOWS
#if
ndef LINUX
len
=
sprintf
(
buffer
,
"%02d/%02d %02d:%02d:%02d.%06d 0x%lld "
,
ptm
->
tm_mon
+
1
,
ptm
->
tm_mday
,
ptm
->
tm_hour
,
ptm
->
tm_min
,
ptm
->
tm_sec
,
(
int
)
timeSecs
.
tv_usec
,
taosGetPthreadId
());
#else
...
...
@@ -436,7 +436,7 @@ void taosPrintLongString(const char *const flags, int dflag, const char *const f
gettimeofday
(
&
timeSecs
,
NULL
);
curTime
=
timeSecs
.
tv_sec
;
ptm
=
localtime_r
(
&
curTime
,
&
Tm
);
#if
def WINDOWS
#if
ndef LINUX
len
=
sprintf
(
buffer
,
"%02d/%02d %02d:%02d:%02d.%06d 0x%lld "
,
ptm
->
tm_mon
+
1
,
ptm
->
tm_mday
,
ptm
->
tm_hour
,
ptm
->
tm_min
,
ptm
->
tm_sec
,
(
int
)
timeSecs
.
tv_usec
,
taosGetPthreadId
());
#else
...
...
@@ -498,7 +498,7 @@ SLogBuff *taosLogBuffNew(int bufSize) {
tLogBuff
->
stop
=
0
;
if
(
pthread_mutex_init
(
&
LOG_BUF_MUTEX
(
tLogBuff
),
NULL
)
<
0
)
goto
_err
;
sem_init
(
&
(
tLogBuff
->
buffNotEmpty
),
0
,
0
);
t
sem_init
(
&
(
tLogBuff
->
buffNotEmpty
),
0
,
0
);
return
tLogBuff
;
...
...
@@ -509,7 +509,7 @@ _err:
}
void
taosLogBuffDestroy
(
SLogBuff
*
tLogBuff
)
{
sem_destroy
(
&
(
tLogBuff
->
buffNotEmpty
));
t
sem_destroy
(
&
(
tLogBuff
->
buffNotEmpty
));
pthread_mutex_destroy
(
&
(
tLogBuff
->
buffMutex
));
free
(
tLogBuff
->
buffer
);
tfree
(
tLogBuff
);
...
...
@@ -547,7 +547,7 @@ int taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int msgLen) {
// TODO : put string in the buffer
sem_post
(
&
(
tLogBuff
->
buffNotEmpty
));
t
sem_post
(
&
(
tLogBuff
->
buffNotEmpty
));
pthread_mutex_unlock
(
&
LOG_BUF_MUTEX
(
tLogBuff
));
...
...
@@ -587,7 +587,7 @@ void *taosAsyncOutputLog(void *param) {
char
tempBuffer
[
TSDB_DEFAULT_LOG_BUF_UNIT
];
while
(
1
)
{
sem_wait
(
&
(
tLogBuff
->
buffNotEmpty
));
t
sem_wait
(
&
(
tLogBuff
->
buffNotEmpty
));
// Polling the buffer
while
(
1
)
{
...
...
src/util/src/tmodule.c
浏览文件 @
1dcdccb7
...
...
@@ -57,13 +57,13 @@ int taosInitModule(module_t *pMod) {
return
-
1
;
}
if
(
sem_init
(
&
pMod
->
emptySem
,
0
,
(
unsigned
int
)
pMod
->
queueSize
)
!=
0
)
{
if
(
t
sem_init
(
&
pMod
->
emptySem
,
0
,
(
unsigned
int
)
pMod
->
queueSize
)
!=
0
)
{
printf
(
"ERROR: init %s empty semaphore failed, reason:%s
\n
"
,
pMod
->
name
,
strerror
(
errno
));
taosCleanUpModule
(
pMod
);
return
-
1
;
}
if
(
sem_init
(
&
pMod
->
fullSem
,
0
,
0
)
!=
0
)
{
if
(
t
sem_init
(
&
pMod
->
fullSem
,
0
,
0
)
!=
0
)
{
printf
(
"ERROR: init %s full semaphore failed, reason:%s
\n
"
,
pMod
->
name
,
strerror
(
errno
));
taosCleanUpModule
(
pMod
);
return
-
1
;
...
...
@@ -103,7 +103,7 @@ void *taosProcessQueue(void *param) {
signal
(
SIGINT
,
SIG_IGN
);
while
(
1
)
{
if
(
sem_wait
(
&
pMod
->
fullSem
)
!=
0
)
if
(
t
sem_wait
(
&
pMod
->
fullSem
)
!=
0
)
printf
(
"ERROR: wait %s fullSem failed, reason:%s
\n
"
,
pMod
->
name
,
strerror
(
errno
));
if
(
pthread_mutex_lock
(
&
pMod
->
queueMutex
)
!=
0
)
...
...
@@ -116,7 +116,7 @@ void *taosProcessQueue(void *param) {
if
(
pthread_mutex_unlock
(
&
pMod
->
queueMutex
)
!=
0
)
printf
(
"ERROR: unlock %s queueMutex failed, reason:%s
\n
"
,
pMod
->
name
,
strerror
(
errno
));
if
(
sem_post
(
&
pMod
->
emptySem
)
!=
0
)
if
(
t
sem_post
(
&
pMod
->
emptySem
)
!=
0
)
printf
(
"ERROR: post %s emptySem failed, reason:%s
\n
"
,
pMod
->
name
,
strerror
(
errno
));
/* process the message */
...
...
@@ -142,7 +142,7 @@ void *taosProcessQueue(void *param) {
}
int
taosSendMsgToModule
(
module_t
*
pMod
,
int
cid
,
int
mid
,
int
tid
,
char
*
msg
)
{
if
(
sem_wait
(
&
pMod
->
emptySem
)
!=
0
)
if
(
t
sem_wait
(
&
pMod
->
emptySem
)
!=
0
)
printf
(
"ERROR: wait %s emptySem failed, reason:%s
\n
"
,
pMod
->
name
,
strerror
(
errno
));
if
(
pthread_mutex_lock
(
&
pMod
->
queueMutex
)
!=
0
)
...
...
@@ -157,7 +157,7 @@ int taosSendMsgToModule(module_t *pMod, int cid, int mid, int tid, char *msg) {
if
(
pthread_mutex_unlock
(
&
pMod
->
queueMutex
)
!=
0
)
printf
(
"ERROR: unlock %s queueMutex failed, reason:%s
\n
"
,
pMod
->
name
,
strerror
(
errno
));
if
(
sem_post
(
&
pMod
->
fullSem
)
!=
0
)
printf
(
"ERROR: post %s fullSem failed, reason:%s
\n
"
,
pMod
->
name
,
strerror
(
errno
));
if
(
t
sem_post
(
&
pMod
->
fullSem
)
!=
0
)
printf
(
"ERROR: post %s fullSem failed, reason:%s
\n
"
,
pMod
->
name
,
strerror
(
errno
));
return
0
;
}
...
...
@@ -173,8 +173,8 @@ void taosCleanUpModule(module_t *pMod) {
}
taosResetPthread
(
&
pMod
->
thread
);
sem_destroy
(
&
pMod
->
emptySem
);
sem_destroy
(
&
pMod
->
fullSem
);
t
sem_destroy
(
&
pMod
->
emptySem
);
t
sem_destroy
(
&
pMod
->
fullSem
);
pthread_mutex_destroy
(
&
pMod
->
queueMutex
);
pthread_mutex_destroy
(
&
pMod
->
stmMutex
);
...
...
src/util/src/tsched.c
浏览文件 @
1dcdccb7
...
...
@@ -27,8 +27,8 @@
typedef
struct
{
char
label
[
16
];
sem_t
emptySem
;
sem_t
fullSem
;
tsem_t
emptySem
;
tsem_t
fullSem
;
pthread_mutex_t
queueMutex
;
int
fullSlot
;
int
emptySlot
;
...
...
@@ -59,12 +59,12 @@ void *taosInitScheduler(int queueSize, int numOfThreads, const char *label) {
goto
_error
;
}
if
(
sem_init
(
&
pSched
->
emptySem
,
0
,
(
unsigned
int
)
pSched
->
queueSize
)
!=
0
)
{
if
(
t
sem_init
(
&
pSched
->
emptySem
,
0
,
(
unsigned
int
)
pSched
->
queueSize
)
!=
0
)
{
pError
(
"init %s:empty semaphore failed, reason:%s"
,
pSched
->
label
,
strerror
(
errno
));
goto
_error
;
}
if
(
sem_init
(
&
pSched
->
fullSem
,
0
,
0
)
!=
0
)
{
if
(
t
sem_init
(
&
pSched
->
fullSem
,
0
,
0
)
!=
0
)
{
pError
(
"init %s:full semaphore failed, reason:%s"
,
pSched
->
label
,
strerror
(
errno
));
goto
_error
;
}
...
...
@@ -109,7 +109,7 @@ void *taosProcessSchedQueue(void *param) {
SSchedQueue
*
pSched
=
(
SSchedQueue
*
)
param
;
while
(
1
)
{
if
(
sem_wait
(
&
pSched
->
fullSem
)
!=
0
)
{
if
(
t
sem_wait
(
&
pSched
->
fullSem
)
!=
0
)
{
if
(
errno
==
EINTR
)
{
/* sem_wait is interrupted by interrupt, ignore and continue */
pTrace
(
"wait %s fullSem was interrupted"
,
pSched
->
label
);
...
...
@@ -128,7 +128,7 @@ void *taosProcessSchedQueue(void *param) {
if
(
pthread_mutex_unlock
(
&
pSched
->
queueMutex
)
!=
0
)
pError
(
"unlock %s queueMutex failed, reason:%s
\n
"
,
pSched
->
label
,
strerror
(
errno
));
if
(
sem_post
(
&
pSched
->
emptySem
)
!=
0
)
if
(
t
sem_post
(
&
pSched
->
emptySem
)
!=
0
)
pError
(
"post %s emptySem failed, reason:%s
\n
"
,
pSched
->
label
,
strerror
(
errno
));
if
(
msg
.
fp
)
...
...
@@ -145,7 +145,7 @@ int taosScheduleTask(void *qhandle, SSchedMsg *pMsg) {
return
0
;
}
while
(
sem_wait
(
&
pSched
->
emptySem
)
!=
0
)
{
while
(
t
sem_wait
(
&
pSched
->
emptySem
)
!=
0
)
{
if
(
errno
!=
EINTR
)
{
pError
(
"wait %s emptySem failed, reason:%s"
,
pSched
->
label
,
strerror
(
errno
));
break
;
...
...
@@ -162,7 +162,7 @@ int taosScheduleTask(void *qhandle, SSchedMsg *pMsg) {
if
(
pthread_mutex_unlock
(
&
pSched
->
queueMutex
)
!=
0
)
pError
(
"unlock %s queueMutex failed, reason:%s"
,
pSched
->
label
,
strerror
(
errno
));
if
(
sem_post
(
&
pSched
->
fullSem
)
!=
0
)
pError
(
"post %s fullSem failed, reason:%s"
,
pSched
->
label
,
strerror
(
errno
));
if
(
t
sem_post
(
&
pSched
->
fullSem
)
!=
0
)
pError
(
"post %s fullSem failed, reason:%s"
,
pSched
->
label
,
strerror
(
errno
));
return
0
;
}
...
...
@@ -178,8 +178,8 @@ void taosCleanUpScheduler(void *param) {
pthread_join
(
pSched
->
qthread
[
i
],
NULL
);
}
sem_destroy
(
&
pSched
->
emptySem
);
sem_destroy
(
&
pSched
->
fullSem
);
t
sem_destroy
(
&
pSched
->
emptySem
);
t
sem_destroy
(
&
pSched
->
fullSem
);
pthread_mutex_destroy
(
&
pSched
->
queueMutex
);
free
(
pSched
->
queue
);
...
...
src/util/src/tsocket.c
浏览文件 @
1dcdccb7
...
...
@@ -301,14 +301,12 @@ int taosOpenUdpSocket(char *ip, short port) {
nocheck
=
1
;
if
(
taosSetSockOpt
(
sockFd
,
SOL_SOCKET
,
SO_NO_CHECK
,
(
void
*
)
&
nocheck
,
sizeof
(
nocheck
))
<
0
)
{
// no_check is not implemented in WSL
// skip the following check if system running WSLv1
if
(
!
taosIsRunningWSLv1
())
{
if
(
!
taosSkipSocketCheck
())
{
pError
(
"setsockopt SO_NO_CHECK failed: %d (%s)"
,
errno
,
strerror
(
errno
));
close
(
sockFd
);
return
-
1
;
}
else
{
p
Error
(
"Skipping: setsockopt SO_NO_CHECK failed
: %d (%s)"
,
errno
,
strerror
(
errno
));
p
Print
(
"Skipping setsockopt SO_NO_CHECK error
: %d (%s)"
,
errno
,
strerror
(
errno
));
}
}
...
...
src/util/src/ttimer.c
浏览文件 @
1dcdccb7
...
...
@@ -46,22 +46,6 @@ char *tmrMemPoolMalloc(mpool_h handle);
void
tmrMemPoolFree
(
mpool_h
handle
,
char
*
p
);
void
tmrMemPoolCleanUp
(
mpool_h
handle
);
#define tmrError(...) \
if (tmrDebugFlag & DEBUG_ERROR) { \
tprintf("ERROR TMR ", tmrDebugFlag, __VA_ARGS__); \
}
#define tmrWarn(...) \
if (tmrDebugFlag & DEBUG_WARN) { \
tprintf("WARN TMR ", tmrDebugFlag, __VA_ARGS__); \
}
#define tmrTrace(...) \
if (tmrDebugFlag & DEBUG_TRACE) { \
tprintf("TMR ", tmrDebugFlag, __VA_ARGS__); \
}
#define maxNumOfTmrCtrl 512
#define MSECONDS_PER_TICK 5
typedef
struct
_tmr_obj
{
void
*
param1
;
void
(
*
fp
)(
void
*
,
void
*
);
...
...
@@ -98,17 +82,17 @@ typedef struct _tmr_ctrl_t {
int
tmrDebugFlag
=
DEBUG_ERROR
|
DEBUG_WARN
|
DEBUG_FILE
;
void
taosTmrProcessList
(
tmr_ctrl_t
*
);
tmr_ctrl_t
tmrCtrl
[
maxNumOfTmrCtrl
];
tmr_ctrl_t
tmrCtrl
[
MAX_NUM_OF_TMRCTL
];
int
numOfTmrCtrl
=
0
;
void
*
tmrIdPool
=
NULL
;
void
*
tmrQhandle
;
int
taosTmrThreads
=
1
;
void
*
taosTimerLoopFunc
(
int
signo
)
{
void
taosTimerLoopFunc
(
int
signo
)
{
tmr_ctrl_t
*
pCtrl
;
int
count
=
0
;
for
(
int
i
=
1
;
i
<
maxNumOfTmrCtrl
;
++
i
)
{
for
(
int
i
=
1
;
i
<
MAX_NUM_OF_TMRCTL
;
++
i
)
{
pCtrl
=
tmrCtrl
+
i
;
if
(
pCtrl
->
signature
)
{
count
++
;
...
...
@@ -120,73 +104,13 @@ void *taosTimerLoopFunc(int signo) {
if
(
count
>=
numOfTmrCtrl
)
break
;
}
}
return
NULL
;
}
#ifndef WINDOWS
void
*
taosProcessAlarmSignal
(
void
*
tharg
)
{
// Block the signal
sigset_t
sigset
;
sigemptyset
(
&
sigset
);
sigaddset
(
&
sigset
,
SIGALRM
);
sigprocmask
(
SIG_BLOCK
,
&
sigset
,
NULL
);
timer_t
timerId
;
struct
sigevent
sevent
;
sevent
.
sigev_notify
=
SIGEV_THREAD_ID
;
sevent
.
_sigev_un
.
_tid
=
syscall
(
__NR_gettid
);
sevent
.
sigev_signo
=
SIGALRM
;
if
(
timer_create
(
CLOCK_REALTIME
,
&
sevent
,
&
timerId
)
==
-
1
)
{
tmrError
(
"Failed to create timer"
);
}
struct
itimerspec
ts
;
ts
.
it_value
.
tv_sec
=
0
;
ts
.
it_value
.
tv_nsec
=
1000000
*
MSECONDS_PER_TICK
;
ts
.
it_interval
.
tv_sec
=
0
;
ts
.
it_interval
.
tv_nsec
=
1000000
*
MSECONDS_PER_TICK
;
if
(
timer_settime
(
timerId
,
0
,
&
ts
,
NULL
))
{
tmrError
(
"Failed to init timer"
);
return
NULL
;
}
int
signo
;
while
(
1
)
{
if
(
sigwait
(
&
sigset
,
&
signo
))
{
tmrError
(
"Failed to wait signal: number %d"
,
signo
);
continue
;
}
/* printf("Signal handling: number %d ......\n", signo); */
taosTimerLoopFunc
(
0
);
}
assert
(
0
);
return
NULL
;
}
#endif
void
taosTmrModuleInit
(
void
)
{
tmrIdPool
=
taosInitIdPool
(
maxNumOfTmrCtrl
);
tmrIdPool
=
taosInitIdPool
(
MAX_NUM_OF_TMRCTL
);
memset
(
tmrCtrl
,
0
,
sizeof
(
tmrCtrl
));
#ifdef LINUX
pthread_t
thread
;
pthread_attr_t
tattr
;
pthread_attr_init
(
&
tattr
);
pthread_attr_setdetachstate
(
&
tattr
,
PTHREAD_CREATE_DETACHED
);
if
(
pthread_create
(
&
thread
,
&
tattr
,
taosProcessAlarmSignal
,
NULL
)
!=
0
)
{
tmrError
(
"failed to create timer thread"
);
return
;
}
pthread_attr_destroy
(
&
tattr
);
#else
taosInitTimer
(
taosTimerLoopFunc
,
MSECONDS_PER_TICK
);
#endif
tmrQhandle
=
taosInitScheduler
(
10000
,
taosTmrThreads
,
"tmr"
);
tmrTrace
(
"timer module is initialized, thread:%d"
,
taosTmrThreads
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录