提交 f41edf3b 编写于 作者: S slzhou

Merge branch '3.0' of github.com:taosdata/TDengine into 3.0_udfd

cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
set(CMAKE_VERBOSE_MAKEFILE ON)
#set output directory #set output directory
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib) SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/bin) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/bin)
...@@ -43,11 +45,14 @@ ENDIF () ...@@ -43,11 +45,14 @@ ENDIF ()
IF (TD_WINDOWS) IF (TD_WINDOWS)
MESSAGE("${Yellow} set compiler flag for Windows! ${ColourReset}") MESSAGE("${Yellow} set compiler flag for Windows! ${ColourReset}")
SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE) SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE)
SET(COMMON_FLAGS "/nologo /WX /wd4018 /wd4999 /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-") SET(COMMON_FLAGS "/W3 /D_WIN32")
IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900)) # IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900))
SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18") # SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18")
ENDIF () # ENDIF ()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS}")
ELSE () ELSE ()
IF (${SANITIZER} MATCHES "true") IF (${SANITIZER} MATCHES "true")
......
...@@ -25,9 +25,28 @@ IF(${TD_WINDOWS}) ...@@ -25,9 +25,28 @@ IF(${TD_WINDOWS})
ON ON
) )
ENDIF () MESSAGE("build msvcregex Win32")
option(
BUILD_MSVCREGEX
"If build msvcregex on Windows"
ON
)
IF(${TD_LINUX} MATCHES TRUE) MESSAGE("build wcwidth Win32")
option(
BUILD_WCWIDTH
"If build wcwidth on Windows"
ON
)
MESSAGE("build wingetopt Win32")
option(
BUILD_WINGETOPT
"If build wingetopt on Windows"
ON
)
ENDIF ()
option( option(
BUILD_TEST BUILD_TEST
...@@ -35,8 +54,6 @@ option( ...@@ -35,8 +54,6 @@ option(
ON ON
) )
ENDIF ()
option( option(
BUILD_WITH_LEVELDB BUILD_WITH_LEVELDB
"If build with leveldb" "If build with leveldb"
......
# msvcregex
ExternalProject_Add(msvcregex
GIT_REPOSITORY https://gitee.com/l0km/libgnurx-msvc.git
GIT_TAG master
SOURCE_DIR "${TD_CONTRIB_DIR}/msvcregex"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
ExternalProject_Add(pthread ExternalProject_Add(pthread
GIT_REPOSITORY https://github.com/GerHobbelt/pthread-win32 GIT_REPOSITORY https://github.com/GerHobbelt/pthread-win32
GIT_TAG v3.0.3.1 GIT_TAG v3.0.3.1
SOURCE_DIR "${TD_CONTRIB_DIR}/pthread-win32" SOURCE_DIR "${TD_CONTRIB_DIR}/pthread"
BINARY_DIR "" BINARY_DIR ""
#BUILD_IN_SOURCE TRUE #BUILD_IN_SOURCE TRUE
CONFIGURE_COMMAND "" CONFIGURE_COMMAND ""
......
# wcwidth
ExternalProject_Add(wcwidth
GIT_REPOSITORY https://github.com/fumiyas/wcwidth-cjk.git
GIT_TAG master
SOURCE_DIR "${TD_CONTRIB_DIR}/wcwidth"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
\ No newline at end of file
# wingetopt
ExternalProject_Add(wingetopt
GIT_REPOSITORY https://github.com/alex85k/wingetopt.git
GIT_TAG master
SOURCE_DIR "${TD_CONTRIB_DIR}/wingetopt"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
\ No newline at end of file
...@@ -14,9 +14,24 @@ if(${BUILD_PTHREAD}) ...@@ -14,9 +14,24 @@ if(${BUILD_PTHREAD})
cat("${TD_SUPPORT_DIR}/pthread_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) cat("${TD_SUPPORT_DIR}/pthread_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif() endif()
# gnu regex # iconv
if(${BUILD_GNUREGEX}) if(${BUILD_WITH_ICONV})
cat("${TD_SUPPORT_DIR}/gnuregex_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) cat("${TD_SUPPORT_DIR}/iconv_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()
# msvc regex
if(${BUILD_MSVCREGEX})
cat("${TD_SUPPORT_DIR}/msvcregex_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()
# wcwidth
if(${BUILD_WCWIDTH})
cat("${TD_SUPPORT_DIR}/wcwidth_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()
# wingetopt
if(${BUILD_WINGETOPT})
cat("${TD_SUPPORT_DIR}/wingetopt_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif() endif()
# googletest # googletest
...@@ -99,8 +114,27 @@ if(${BUILD_TEST}) ...@@ -99,8 +114,27 @@ if(${BUILD_TEST})
target_include_directories( target_include_directories(
gtest gtest
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src> PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_linux>
) )
if(${TD_WINDOWS})
target_include_directories(
gtest
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_win>
)
endif(${TD_WINDOWS})
if(${TD_LINUX})
target_include_directories(
gtest
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_linux>
)
endif(${TD_LINUX})
if(${TD_DARWIN})
target_include_directories(
gtest
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_darwin>
)
endif(${TD_DARWIN})
endif(${BUILD_TEST}) endif(${BUILD_TEST})
# cJson # cJson
...@@ -182,6 +216,53 @@ if(${BUILD_WITH_NURAFT}) ...@@ -182,6 +216,53 @@ if(${BUILD_WITH_NURAFT})
add_subdirectory(nuraft) add_subdirectory(nuraft)
endif(${BUILD_WITH_NURAFT}) endif(${BUILD_WITH_NURAFT})
# pthread
if(${BUILD_PTHREAD})
set(CMAKE_BUILD_TYPE release)
add_definitions(-DPTW32_STATIC_LIB)
add_subdirectory(pthread)
set_target_properties(libpthreadVC3 PROPERTIES OUTPUT_NAME pthread)
add_library(pthread STATIC IMPORTED GLOBAL)
SET_PROPERTY(TARGET pthread PROPERTY IMPORTED_LOCATION ${LIBRARY_OUTPUT_PATH}/pthread.lib)
endif()
# iconv
if(${BUILD_WITH_ICONV})
add_subdirectory(iconv)
endif(${BUILD_WITH_ICONV})
# wingetopt
if(${BUILD_WINGETOPT})
add_subdirectory(wingetopt)
endif(${BUILD_WINGETOPT})
# msvcregex
if(${BUILD_MSVCREGEX})
add_library(msvcregex STATIC "")
target_sources(msvcregex
PRIVATE "msvcregex/regex.c"
)
target_include_directories(msvcregex
PRIVATE "msvcregex"
)
target_link_libraries(msvcregex
INTERFACE Shell32
)
SET_TARGET_PROPERTIES(msvcregex PROPERTIES OUTPUT_NAME msvcregex)
endif(${BUILD_MSVCREGEX})
# msvcregex
if(${BUILD_WCWIDTH})
add_library(wcwidth STATIC "")
target_sources(wcwidth
PRIVATE "wcwidth/wcwidth.c"
)
target_include_directories(wcwidth
PRIVATE "wcwidth"
)
SET_TARGET_PROPERTIES(wcwidth PROPERTIES OUTPUT_NAME wcwidth)
endif(${BUILD_WCWIDTH})
# CRAFT # CRAFT
if(${BUILD_WITH_CRAFT}) if(${BUILD_WITH_CRAFT})
add_library(craft STATIC IMPORTED GLOBAL) add_library(craft STATIC IMPORTED GLOBAL)
...@@ -238,8 +319,12 @@ if(${BUILD_WITH_SQLITE}) ...@@ -238,8 +319,12 @@ if(${BUILD_WITH_SQLITE})
target_link_libraries(sqlite target_link_libraries(sqlite
INTERFACE m INTERFACE m
INTERFACE pthread INTERFACE pthread
INTERFACE dl
) )
if(NOT TD_WINDOWS)
target_link_libraries(sqlite
INTERFACE dl
)
endif(NOT TD_WINDOWS)
endif(${BUILD_WITH_SQLITE}) endif(${BUILD_WITH_SQLITE})
# pthread # pthread
......
add_executable(simulate_vnode "simulate_vnode.c") add_executable(simulate_vnode "simulate_vnode.c")
target_link_libraries(simulate_vnode PUBLIC craft lz4 uv_a) target_link_libraries(simulate_vnode PUBLIC craft lz4 uv_a)
\ No newline at end of file if(${BUILD_WINGETOPT})
target_link_libraries(simulate_vnode PUBLIC wingetopt)
target_include_directories(
simulate_vnode
PUBLIC "${TD_SOURCE_DIR}/contrib/wingetopt/src"
)
endif()
\ No newline at end of file
...@@ -6,43 +6,39 @@ ...@@ -6,43 +6,39 @@
#define POINTER_SHIFT(ptr, s) ((void *)(((char *)ptr) + (s))) #define POINTER_SHIFT(ptr, s) ((void *)(((char *)ptr) + (s)))
#define POINTER_DISTANCE(pa, pb) ((char *)(pb) - (char *)(pa)) #define POINTER_DISTANCE(pa, pb) ((char *)(pb) - (char *)(pa))
#define tPutA(buf, val) \ static inline void tPutA(void **buf, uint64_t val) {
({ \ memcpy(buf, &val, sizeof(val));
memcpy(buf, &val, sizeof(val)); \ *buf = POINTER_SHIFT(buf, sizeof(val));
POINTER_SHIFT(buf, sizeof(val)); \ }
})
#define tPutB(buf, val) \ static inline void tPutB(void **buf, uint64_t val) {
({ \ ((uint8_t *)buf)[7] = ((val) >> 56) & 0xff;
((uint8_t *)buf)[7] = ((val) >> 56) & 0xff; \ ((uint8_t *)buf)[6] = ((val) >> 48) & 0xff;
((uint8_t *)buf)[6] = ((val) >> 48) & 0xff; \ ((uint8_t *)buf)[5] = ((val) >> 40) & 0xff;
((uint8_t *)buf)[5] = ((val) >> 40) & 0xff; \ ((uint8_t *)buf)[4] = ((val) >> 32) & 0xff;
((uint8_t *)buf)[4] = ((val) >> 32) & 0xff; \ ((uint8_t *)buf)[3] = ((val) >> 24) & 0xff;
((uint8_t *)buf)[3] = ((val) >> 24) & 0xff; \ ((uint8_t *)buf)[2] = ((val) >> 16) & 0xff;
((uint8_t *)buf)[2] = ((val) >> 16) & 0xff; \ ((uint8_t *)buf)[1] = ((val) >> 8) & 0xff;
((uint8_t *)buf)[1] = ((val) >> 8) & 0xff; \ ((uint8_t *)buf)[0] = (val)&0xff;
((uint8_t *)buf)[0] = (val)&0xff; \ *buf = POINTER_SHIFT(buf, sizeof(val));
POINTER_SHIFT(buf, sizeof(val)); \ }
})
#define tPutC(buf, val) \ static inline void tPutC(void **buf, uint64_t val) {
({ \ if (buf) {
if (buf) { \ ((uint64_t *)buf)[0] = (val);
((uint64_t *)buf)[0] = (val); \ POINTER_SHIFT(buf, sizeof(val));
POINTER_SHIFT(buf, sizeof(val)); \ }
} \ *buf = NULL;
NULL; \ }
})
#define tPutD(buf, val) \ static inline void tPutD(void **buf, uint64_t val) {
({ \ uint64_t tmp = val;
uint64_t tmp = val; \ for (size_t i = 0; i < sizeof(val); i++) {
for (size_t i = 0; i < sizeof(val); i++) { \ ((uint8_t *)buf)[i] = tmp & 0xff;
((uint8_t *)buf)[i] = tmp & 0xff; \ tmp >>= 8;
tmp >>= 8; \ }
} \ *buf = POINTER_SHIFT(buf, sizeof(val));
POINTER_SHIFT(buf, sizeof(val)); \ }
})
static inline void tPutE(void **buf, uint64_t val) { static inline void tPutE(void **buf, uint64_t val) {
if (buf) { if (buf) {
...@@ -61,7 +57,7 @@ static void func(T t) { ...@@ -61,7 +57,7 @@ static void func(T t) {
switch (t) { switch (t) {
case A: case A:
for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) { for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) {
pBuf = tPutA(pBuf, val); tPutA(pBuf, val);
if (POINTER_DISTANCE(buf, pBuf) == 1024) { if (POINTER_DISTANCE(buf, pBuf) == 1024) {
pBuf = buf; pBuf = buf;
} }
...@@ -69,7 +65,7 @@ static void func(T t) { ...@@ -69,7 +65,7 @@ static void func(T t) {
break; break;
case B: case B:
for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) { for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) {
pBuf = tPutB(pBuf, val); tPutB(pBuf, val);
if (POINTER_DISTANCE(buf, pBuf) == 1024) { if (POINTER_DISTANCE(buf, pBuf) == 1024) {
pBuf = buf; pBuf = buf;
} }
...@@ -77,7 +73,7 @@ static void func(T t) { ...@@ -77,7 +73,7 @@ static void func(T t) {
break; break;
case C: case C:
for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) { for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) {
pBuf = tPutC(pBuf, val); tPutC(pBuf, val);
if (POINTER_DISTANCE(buf, pBuf) == 1024) { if (POINTER_DISTANCE(buf, pBuf) == 1024) {
pBuf = buf; pBuf = buf;
} }
...@@ -85,7 +81,7 @@ static void func(T t) { ...@@ -85,7 +81,7 @@ static void func(T t) {
break; break;
case D: case D:
for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) { for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) {
pBuf = tPutD(pBuf, val); tPutD(pBuf, val);
if (POINTER_DISTANCE(buf, pBuf) == 1024) { if (POINTER_DISTANCE(buf, pBuf) == 1024) {
pBuf = buf; pBuf = buf;
} }
......
...@@ -39,6 +39,7 @@ target_include_directories(tstream ...@@ -39,6 +39,7 @@ target_include_directories(tstream
target_include_directories(demoapi target_include_directories(demoapi
PUBLIC "${TD_SOURCE_DIR}/include/client" PUBLIC "${TD_SOURCE_DIR}/include/client"
PUBLIC "${TD_SOURCE_DIR}/include/os"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
) )
......
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> // #include <unistd.h>
#include <inttypes.h> #include <inttypes.h>
#ifndef WINDOWS
#include <argp.h> #include <argp.h>
#endif
#include "osSleep.h"
#include "taos.h" #include "taos.h"
#define debugPrint(fmt, ...) \ #define debugPrint(fmt, ...) \
...@@ -32,6 +34,7 @@ ...@@ -32,6 +34,7 @@
int64_t g_num_of_tb = 2; int64_t g_num_of_tb = 2;
int64_t g_num_of_rec = 3; int64_t g_num_of_rec = 3;
#ifndef WINDOWS
static struct argp_option options[] = { static struct argp_option options[] = {
{"tables", 't', "NUMBER", 0, "Number of child tables, default is 10000."}, {"tables", 't', "NUMBER", 0, "Number of child tables, default is 10000."},
{"records", 'n', "NUMBER", 0, {"records", 'n', "NUMBER", 0,
...@@ -61,16 +64,16 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -61,16 +64,16 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
} }
static struct argp argp = {options, parse_opt, "", ""}; static struct argp argp = {options, parse_opt, "", ""};
#endif
static void prepare_data(TAOS* taos) { static void prepare_data(TAOS* taos) {
TAOS_RES *res; TAOS_RES *res;
res = taos_query(taos, "drop database if exists test;"); res = taos_query(taos, "drop database if exists test;");
taos_free_result(res); taos_free_result(res);
usleep(100000); taosMsleep(100);
res = taos_query(taos, "create database test;"); res = taos_query(taos, "create database test;");
taos_free_result(res); taos_free_result(res);
usleep(100000); taosMsleep(100);
taos_select_db(taos, "test"); taos_select_db(taos, "test");
char command[1024] = {0}; char command[1024] = {0};
...@@ -87,18 +90,17 @@ static void prepare_data(TAOS* taos) { ...@@ -87,18 +90,17 @@ static void prepare_data(TAOS* taos) {
taos_free_result(res); taos_free_result(res);
for (int64_t i = 0; i < g_num_of_tb; i ++) { for (int64_t i = 0; i < g_num_of_tb; i ++) {
// sprintf(command, "create table t%"PRId64" using meters "
// "tags(%"PRId64", '%s', '%s', '%s');",
// i, i, (i%2)?"beijing":"shanghai",
// (i%2)?"朝阳区":"黄浦区",
// (i%2)?"长安街":"中山路");
sprintf(command, "create table t%"PRId64" using meters " sprintf(command, "create table t%"PRId64" using meters "
"tags(%"PRId64", '%s', '%s', '%s');",
i, i, (i%2)?"beijing":"shanghai",
(i%2)?"朝阳区":"黄浦区",
(i%2)?"长安街":"中山路");
/* sprintf(command, "create table t%"PRId64" using meters "
"tags(%"PRId64", '%s', '%s', '%s');", "tags(%"PRId64", '%s', '%s', '%s');",
i, i, i, i,
(i%2)?"beijing":"shanghai", (i%2)?"beijing":"shanghai",
(i%2)?"chaoyang":"huangpu", (i%2)?"chaoyang":"huangpu",
(i%2?"changan street":"jianguo rd")); (i%2?"changan street":"jianguo rd"));
*/
res = taos_query(taos, command); res = taos_query(taos, command);
if ((res) && (0 == taos_errno(res))) { if ((res) && (0 == taos_errno(res))) {
okPrint("t%" PRId64 " created\n", i); okPrint("t%" PRId64 " created\n", i);
...@@ -117,7 +119,8 @@ static void prepare_data(TAOS* taos) { ...@@ -117,7 +119,8 @@ static void prepare_data(TAOS* taos) {
"'%c%d', '%s%c%d', '%c%d')", "'%c%d', '%s%c%d', '%c%d')",
i, 1650000000000+j, (float)j, j, i, 1650000000000+j, (float)j, j,
'a'+(int)j%25, rand(), 'a'+(int)j%25, rand(),
"涛思", 'z' - (int)j%25, rand(), // "涛思", 'z' - (int)j%25, rand(),
"TAOS", 'z' - (int)j%25, rand(),
'b' - (int)j%25, rand() 'b' - (int)j%25, rand()
); );
res = taos_query(taos, command); res = taos_query(taos, command);
...@@ -196,7 +199,7 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { ...@@ -196,7 +199,7 @@ static int print_result(char *tbname, TAOS_RES* res, int block) {
printf("col%d, row: %"PRId64", " printf("col%d, row: %"PRId64", "
"value: %"PRId64"\n", "value: %"PRId64"\n",
f, c, f, c,
*(int64_t*)(row[f]+c*sizeof(int64_t))); *(int64_t*)((char*)(row[f])+c*sizeof(int64_t)));
} }
break; break;
...@@ -208,7 +211,7 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { ...@@ -208,7 +211,7 @@ static int print_result(char *tbname, TAOS_RES* res, int block) {
printf("col%d, row: %"PRId64", " printf("col%d, row: %"PRId64", "
"value: %d\n", "value: %d\n",
f, c, f, c,
*(int32_t*)(row[f]+c*sizeof(int32_t))); *(int32_t*)((char*)(row[f])+c*sizeof(int32_t)));
} }
break; break;
...@@ -220,7 +223,7 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { ...@@ -220,7 +223,7 @@ static int print_result(char *tbname, TAOS_RES* res, int block) {
printf("col%d, row: %"PRId64", " printf("col%d, row: %"PRId64", "
"value: %f\n", "value: %f\n",
f, c, f, c,
*(float*)(row[f]+c*sizeof(float))); *(float*)((char*)(row[f])+c*sizeof(float)));
} }
break; break;
...@@ -235,9 +238,9 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { ...@@ -235,9 +238,9 @@ static int print_result(char *tbname, TAOS_RES* res, int block) {
if (offsets) { if (offsets) {
for (int c = 0; c < rows; c++) { for (int c = 0; c < rows; c++) {
if (offsets[c] != -1) { if (offsets[c] != -1) {
int length = *(int16_t*)(row[f] + offsets[c]); int length = *(int16_t*)((char*)(row[f]) + offsets[c]);
char *buf = calloc(1, length + 1); char *buf = calloc(1, length + 1);
strncpy(buf, (char *)(row[f] + offsets[c] + 2), length); strncpy(buf, (char *)((char*)(row[f]) + offsets[c] + 2), length);
printf("row: %d, col: %d, offset: %d, length: %d, content: %s\n", printf("row: %d, col: %d, offset: %d, length: %d, content: %s\n",
c, f, offsets[c], length, buf); c, f, offsets[c], length, buf);
free(buf); free(buf);
...@@ -314,8 +317,9 @@ int main(int argc, char *argv[]) { ...@@ -314,8 +317,9 @@ int main(int argc, char *argv[]) {
const char* host = "127.0.0.1"; const char* host = "127.0.0.1";
const char* user = "root"; const char* user = "root";
const char* passwd = "taosdata"; const char* passwd = "taosdata";
#ifndef WINDOWS
argp_parse(&argp, argc, argv, 0, 0, NULL); argp_parse(&argp, argc, argv, 0, 0, NULL);
#endif
TAOS* taos = taos_connect(host, user, passwd, "", 0); TAOS* taos = taos_connect(host, user, passwd, "", 0);
if (taos == NULL) { if (taos == NULL) {
printf("\033[31mfailed to connect to db, reason:%s\033[0m\n", taos_errstr(taos)); printf("\033[31mfailed to connect to db, reason:%s\033[0m\n", taos_errstr(taos));
......
...@@ -1359,7 +1359,7 @@ static void tdSRowPrint(STSRow *row, STSchema *pSchema) { ...@@ -1359,7 +1359,7 @@ static void tdSRowPrint(STSRow *row, STSchema *pSchema) {
printf(">>>"); printf(">>>");
for (int i = 0; i < pSchema->numOfCols; ++i) { for (int i = 0; i < pSchema->numOfCols; ++i) {
STColumn *stCol = pSchema->columns + i; STColumn *stCol = pSchema->columns + i;
SCellVal sVal = {.valType = 255, .val = NULL}; SCellVal sVal = { 255, NULL};
if (!tdSTSRowIterNext(&iter, stCol->colId, stCol->type, &sVal)) { if (!tdSTSRowIterNext(&iter, stCol->colId, stCol->type, &sVal)) {
break; break;
} }
......
...@@ -26,6 +26,9 @@ extern "C" { ...@@ -26,6 +26,9 @@ extern "C" {
typedef struct SBnode SBnode; typedef struct SBnode SBnode;
typedef struct { typedef struct {
#ifdef WINDOWS
size_t avoidCompilationErrors;
#endif
} SBnodeLoad; } SBnodeLoad;
typedef struct { typedef struct {
......
...@@ -51,6 +51,10 @@ typedef struct STableComInfo { ...@@ -51,6 +51,10 @@ typedef struct STableComInfo {
typedef struct SIndexMeta { typedef struct SIndexMeta {
#ifdef WINDOWS
size_t avoidCompilationErrors;
#endif
} SIndexMeta; } SIndexMeta;
......
...@@ -22,7 +22,6 @@ extern "C" { ...@@ -22,7 +22,6 @@ extern "C" {
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <semaphore.h>
#include <regex.h> #include <regex.h>
...@@ -51,6 +50,15 @@ extern "C" { ...@@ -51,6 +50,15 @@ extern "C" {
#include <sys/prctl.h> #include <sys/prctl.h>
#include <argp.h> #include <argp.h>
#endif #endif
#else
#include <time.h>
#ifndef TD_USE_WINSOCK
#include <winsock2.h>
#else
#include <winsock.h>
#endif
#endif #endif
......
...@@ -63,22 +63,22 @@ int8_t atomic_add_fetch_8(int8_t volatile *ptr, int8_t val); ...@@ -63,22 +63,22 @@ int8_t atomic_add_fetch_8(int8_t volatile *ptr, int8_t val);
int16_t atomic_add_fetch_16(int16_t volatile *ptr, int16_t val); int16_t atomic_add_fetch_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_add_fetch_32(int32_t volatile *ptr, int32_t val); int32_t atomic_add_fetch_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_add_fetch_64(int64_t volatile *ptr, int64_t val); int64_t atomic_add_fetch_64(int64_t volatile *ptr, int64_t val);
void* atomic_add_fetch_ptr(void *ptr, int32_t val); void* atomic_add_fetch_ptr(void *ptr, void *val);
int8_t atomic_fetch_add_8(int8_t volatile *ptr, int8_t val); int8_t atomic_fetch_add_8(int8_t volatile *ptr, int8_t val);
int16_t atomic_fetch_add_16(int16_t volatile *ptr, int16_t val); int16_t atomic_fetch_add_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_fetch_add_32(int32_t volatile *ptr, int32_t val); int32_t atomic_fetch_add_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_fetch_add_64(int64_t volatile *ptr, int64_t val); int64_t atomic_fetch_add_64(int64_t volatile *ptr, int64_t val);
void* atomic_fetch_add_ptr(void *ptr, int32_t val); void* atomic_fetch_add_ptr(void *ptr, void *val);
int8_t atomic_sub_fetch_8(int8_t volatile *ptr, int8_t val); int8_t atomic_sub_fetch_8(int8_t volatile *ptr, int8_t val);
int16_t atomic_sub_fetch_16(int16_t volatile *ptr, int16_t val); int16_t atomic_sub_fetch_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_sub_fetch_32(int32_t volatile *ptr, int32_t val); int32_t atomic_sub_fetch_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_sub_fetch_64(int64_t volatile *ptr, int64_t val); int64_t atomic_sub_fetch_64(int64_t volatile *ptr, int64_t val);
void* atomic_sub_fetch_ptr(void *ptr, int32_t val); void* atomic_sub_fetch_ptr(void *ptr, void *val);
int8_t atomic_fetch_sub_8(int8_t volatile *ptr, int8_t val); int8_t atomic_fetch_sub_8(int8_t volatile *ptr, int8_t val);
int16_t atomic_fetch_sub_16(int16_t volatile *ptr, int16_t val); int16_t atomic_fetch_sub_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_fetch_sub_32(int32_t volatile *ptr, int32_t val); int32_t atomic_fetch_sub_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_fetch_sub_64(int64_t volatile *ptr, int64_t val); int64_t atomic_fetch_sub_64(int64_t volatile *ptr, int64_t val);
void* atomic_fetch_sub_ptr(void *ptr, int32_t val); void* atomic_fetch_sub_ptr(void *ptr, void *val);
int8_t atomic_and_fetch_8(int8_t volatile *ptr, int8_t val); int8_t atomic_and_fetch_8(int8_t volatile *ptr, int8_t val);
int16_t atomic_and_fetch_16(int16_t volatile *ptr, int16_t val); int16_t atomic_and_fetch_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_and_fetch_32(int32_t volatile *ptr, int32_t val); int32_t atomic_and_fetch_32(int32_t volatile *ptr, int32_t val);
......
...@@ -191,7 +191,7 @@ extern "C" { ...@@ -191,7 +191,7 @@ extern "C" {
#define threadlocal __declspec( thread ) #define threadlocal __declspec( thread )
#endif #endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#define PRIzu "ld" #define PRIzu "ld"
#else #else
#define PRIzu "zu" #define PRIzu "zu"
......
...@@ -36,12 +36,12 @@ typedef struct TdDirEntry *TdDirEntryPtr; ...@@ -36,12 +36,12 @@ typedef struct TdDirEntry *TdDirEntryPtr;
void taosRemoveDir(const char *dirname); void taosRemoveDir(const char *dirname);
bool taosDirExist(char *dirname); bool taosDirExist(const char *dirname);
int32_t taosMkDir(const char *dirname); int32_t taosMkDir(const char *dirname);
int32_t taosMulMkDir(const char *dirname); int32_t taosMulMkDir(const char *dirname);
void taosRemoveOldFiles(const char *dirname, int32_t keepDays); 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);
int32_t taosRealPath(char *dirname, int32_t maxlen); int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen);
bool taosIsDir(const char *dirname); bool taosIsDir(const char *dirname);
char* taosDirName(char *dirname); char* taosDirName(char *dirname);
char* taosDirEntryBaseName(char *dirname); char* taosDirEntryBaseName(char *dirname);
...@@ -50,7 +50,7 @@ TdDirPtr taosOpenDir(const char *dirname); ...@@ -50,7 +50,7 @@ TdDirPtr taosOpenDir(const char *dirname);
TdDirEntryPtr taosReadDir(TdDirPtr pDir); TdDirEntryPtr taosReadDir(TdDirPtr pDir);
bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry); bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry);
char* taosGetDirEntryName(TdDirEntryPtr pDirEntry); char* taosGetDirEntryName(TdDirEntryPtr pDirEntry);
int32_t taosCloseDir(TdDirPtr pDir); int32_t taosCloseDir(TdDirPtr *ppDir);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -93,7 +93,6 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, ...@@ -93,7 +93,6 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix,
int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size); int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size);
void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length);
bool taosValidFile(TdFilePtr pFile); bool taosValidFile(TdFilePtr pFile);
int32_t taosGetErrorFile(TdFilePtr pFile); int32_t taosGetErrorFile(TdFilePtr pFile);
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
int32_t BUILDIN_CLZL(uint64_t val); int32_t BUILDIN_CLZL(uint64_t val);
int32_t BUILDIN_CLZ(uint32_t val); int32_t BUILDIN_CLZ(uint32_t val);
int32_t BUILDIN_CTZL(uint64_t val); int32_t BUILDIN_CTZL(uint64_t val);
......
...@@ -23,7 +23,7 @@ extern "C" { ...@@ -23,7 +23,7 @@ extern "C" {
#define TPOW2(x) ((x) * (x)) #define TPOW2(x) ((x) * (x))
#define TABS(x) ((x) > 0 ? (x) : -(x)) #define TABS(x) ((x) > 0 ? (x) : -(x))
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#define TSWAP(a, b, c) \ #define TSWAP(a, b, c) \
do { \ do { \
...@@ -33,6 +33,7 @@ extern "C" { ...@@ -33,6 +33,7 @@ extern "C" {
} while (0) } while (0)
#define TMAX(a, b) (((a) > (b)) ? (a) : (b)) #define TMAX(a, b) (((a) > (b)) ? (a) : (b))
#define TMIN(a, b) (((a) < (b)) ? (a) : (b)) #define TMIN(a, b) (((a) < (b)) ? (a) : (b))
#define TRANGE(aa, bb, cc) ((aa) = TMAX((aa), (bb)),(aa) = TMIN((aa), (cc)))
#else #else
......
...@@ -19,32 +19,53 @@ ...@@ -19,32 +19,53 @@
// If the error is in a third-party library, place this header file under the third-party library header file. // If the error is in a third-party library, place this header file under the third-party library header file.
// When you want to use this feature, you should find or add the same function in the following section. // When you want to use this feature, you should find or add the same function in the following section.
#ifndef ALLOW_FORBID_FUNC #ifndef ALLOW_FORBID_FUNC
#define socket SOCKET_FUNC_TAOS_FORBID #define socket SOCKET_FUNC_TAOS_FORBID
#define bind BIND_FUNC_TAOS_FORBID #define bind BIND_FUNC_TAOS_FORBID
#define listen LISTEN_FUNC_TAOS_FORBID #define listen LISTEN_FUNC_TAOS_FORBID
#define accept ACCEPT_FUNC_TAOS_FORBID #define accept ACCEPT_FUNC_TAOS_FORBID
#define epoll_create EPOLL_CREATE_FUNC_TAOS_FORBID #define epoll_create EPOLL_CREATE_FUNC_TAOS_FORBID
#define epoll_ctl EPOLL_CTL_FUNC_TAOS_FORBID #define epoll_ctl EPOLL_CTL_FUNC_TAOS_FORBID
#define epoll_wait EPOLL_WAIT_FUNC_TAOS_FORBID #define epoll_wait EPOLL_WAIT_FUNC_TAOS_FORBID
#define inet_addr INET_ADDR_FUNC_TAOS_FORBID #define inet_addr INET_ADDR_FUNC_TAOS_FORBID
#define inet_ntoa INET_NTOA_FUNC_TAOS_FORBID #define inet_ntoa INET_NTOA_FUNC_TAOS_FORBID
#endif #endif
#if defined(WINDOWS) #if defined(WINDOWS)
#include "winsock2.h" #if BYTE_ORDER == LITTLE_ENDIAN
#include <WS2tcpip.h> #include <stdlib.h>
#include <winbase.h> #define htobe16(x) _byteswap_ushort(x)
#include <Winsock2.h> #define htole16(x) (x)
#define be16toh(x) _byteswap_ushort(x)
#define le16toh(x) (x)
#define htobe32(x) _byteswap_ulong(x)
#define htole32(x) (x)
#define be32toh(x) _byteswap_ulong(x)
#define le32toh(x) (x)
#define htobe64(x) _byteswap_uint64(x)
#define htole64(x) (x)
#define be64toh(x) _byteswap_uint64(x)
#define le64toh(x) (x)
#else
#error byte order not supported
#endif
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#define __PDP_ENDIAN PDP_ENDIAN
#else #else
#include <netinet/in.h>
#include <sys/socket.h>
#if defined(_TD_DARWIN_64)
#include <osEok.h>
#else
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/socket.h> #include <sys/epoll.h>
#endif
#if defined(_TD_DARWIN_64)
#include <osEok.h>
#else
#include <netinet/in.h>
#include <sys/epoll.h>
#endif
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
...@@ -52,14 +73,10 @@ extern "C" { ...@@ -52,14 +73,10 @@ extern "C" {
#endif #endif
#if defined(WINDOWS) #if defined(WINDOWS)
#define htobe64 htonll typedef int socklen_t;
#endif
#if defined(WINDOWS)
#define TAOS_EPOLL_WAIT_TIME 100 #define TAOS_EPOLL_WAIT_TIME 100
typedef SOCKET eventfd_t; typedef SOCKET eventfd_t;
#define eventfd(a, b) -1 #define eventfd(a, b) -1
typedef SOCKET EpollFd;
#define EpollClose(pollFd) epoll_close(pollFd) #define EpollClose(pollFd) epoll_close(pollFd)
#ifndef EPOLLWAKEUP #ifndef EPOLLWAKEUP
#define EPOLLWAKEUP (1u << 29) #define EPOLLWAKEUP (1u << 29)
...@@ -79,31 +96,29 @@ extern "C" { ...@@ -79,31 +96,29 @@ extern "C" {
#if defined(_TD_DARWIN_64) #if defined(_TD_DARWIN_64)
// #define htobe64 htonll // #define htobe64 htonll
# include <libkern/OSByteOrder.h> #include <libkern/OSByteOrder.h>
# define htobe16(x) OSSwapHostToBigInt16(x) #define htobe16(x) OSSwapHostToBigInt16(x)
# define htole16(x) OSSwapHostToLittleInt16(x) #define htole16(x) OSSwapHostToLittleInt16(x)
# define be16toh(x) OSSwapBigToHostInt16(x) #define be16toh(x) OSSwapBigToHostInt16(x)
# define le16toh(x) OSSwapLittleToHostInt16(x) #define le16toh(x) OSSwapLittleToHostInt16(x)
# define htobe32(x) OSSwapHostToBigInt32(x) #define htobe32(x) OSSwapHostToBigInt32(x)
# define htole32(x) OSSwapHostToLittleInt32(x) #define htole32(x) OSSwapHostToLittleInt32(x)
# define be32toh(x) OSSwapBigToHostInt32(x) #define be32toh(x) OSSwapBigToHostInt32(x)
# define le32toh(x) OSSwapLittleToHostInt32(x) #define le32toh(x) OSSwapLittleToHostInt32(x)
# define htobe64(x) OSSwapHostToBigInt64(x) #define htobe64(x) OSSwapHostToBigInt64(x)
# define htole64(x) OSSwapHostToLittleInt64(x) #define htole64(x) OSSwapHostToLittleInt64(x)
# define be64toh(x) OSSwapBigToHostInt64(x) #define be64toh(x) OSSwapBigToHostInt64(x)
# define le64toh(x) OSSwapLittleToHostInt64(x) #define le64toh(x) OSSwapLittleToHostInt64(x)
# define __BYTE_ORDER BYTE_ORDER #define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN #define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN #define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN #define __PDP_ENDIAN PDP_ENDIAN
#endif #endif
#define TAOS_EPOLL_WAIT_TIME 500
typedef int32_t SocketFd; typedef int32_t SocketFd;
typedef SocketFd EpollFd; typedef SocketFd EpollFd;
...@@ -122,7 +137,7 @@ typedef struct TdEpoll *TdEpollPtr; ...@@ -122,7 +137,7 @@ typedef struct TdEpoll *TdEpollPtr;
int32_t taosSendto(TdSocketPtr pSocket, void * msg, int len, unsigned int flags, const struct sockaddr * to, int tolen); int32_t taosSendto(TdSocketPtr pSocket, void * msg, int len, unsigned int flags, const struct sockaddr * to, int tolen);
int32_t taosWriteSocket(TdSocketPtr pSocket, void *msg, int len); int32_t taosWriteSocket(TdSocketPtr pSocket, void *msg, int len);
int32_t taosReadSocket(TdSocketPtr pSocket, void *msg, int len); int32_t taosReadSocket(TdSocketPtr pSocket, void *msg, int len);
int32_t taosReadFromSocket(TdSocketPtr pSocket, void *buf, int32_t len, int32_t flags, struct sockaddr *destAddr, socklen_t *addrLen); int32_t taosReadFromSocket(TdSocketPtr pSocket, void *buf, int32_t len, int32_t flags, struct sockaddr *destAddr, int *addrLen);
int32_t taosCloseSocketNoCheck1(SocketFd fd); int32_t taosCloseSocketNoCheck1(SocketFd fd);
int32_t taosCloseSocket(TdSocketPtr *ppSocket); int32_t taosCloseSocket(TdSocketPtr *ppSocket);
int32_t taosCloseSocketServer(TdSocketServerPtr *ppSocketServer); int32_t taosCloseSocketServer(TdSocketServerPtr *ppSocketServer);
...@@ -139,14 +154,15 @@ int32_t taosWriteMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes); ...@@ -139,14 +154,15 @@ int32_t taosWriteMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
int32_t taosReadMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes); int32_t taosReadMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
int32_t taosNonblockwrite(TdSocketPtr pSocket, char *ptr, int32_t nbytes); int32_t taosNonblockwrite(TdSocketPtr pSocket, char *ptr, int32_t nbytes);
int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len); int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len);
void taosWinSocketInit();
TdSocketPtr taosOpenUdpSocket(uint32_t localIp, uint16_t localPort); TdSocketPtr taosOpenUdpSocket(uint32_t localIp, uint16_t localPort);
TdSocketPtr taosOpenTcpClientSocket(uint32_t ip, uint16_t port, uint32_t localIp); TdSocketPtr taosOpenTcpClientSocket(uint32_t ip, uint16_t port, uint32_t localIp);
TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port); TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port);
int32_t taosKeepTcpAlive(TdSocketPtr pSocket); int32_t taosKeepTcpAlive(TdSocketPtr pSocket);
TdSocketPtr taosAcceptTcpConnectSocket(TdSocketServerPtr pServerSocket, struct sockaddr *destAddr, socklen_t *addrLen); TdSocketPtr taosAcceptTcpConnectSocket(TdSocketServerPtr pServerSocket, struct sockaddr *destAddr, int *addrLen);
int32_t taosGetSocketName(TdSocketPtr pSocket,struct sockaddr *destAddr, socklen_t *addrLen); int32_t taosGetSocketName(TdSocketPtr pSocket,struct sockaddr *destAddr, int *addrLen);
void taosBlockSIGPIPE(); void taosBlockSIGPIPE();
uint32_t taosGetIpv4FromFqdn(const char *); uint32_t taosGetIpv4FromFqdn(const char *);
......
...@@ -39,7 +39,7 @@ typedef int32_t TdUcs4; ...@@ -39,7 +39,7 @@ typedef int32_t TdUcs4;
#define wchar_t WCHAR_T_TYPE_TAOS_FORBID #define wchar_t WCHAR_T_TYPE_TAOS_FORBID
#endif #endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#define tstrdup(str) _strdup(str) #define tstrdup(str) _strdup(str)
#else #else
#define tstrdup(str) strdup(str) #define tstrdup(str) strdup(str)
......
...@@ -22,9 +22,12 @@ ...@@ -22,9 +22,12 @@
extern "C" { extern "C" {
#endif #endif
#ifndef WINDOWS
#ifndef __USE_XOPEN2K #ifndef __USE_XOPEN2K
#define TD_USE_SPINLOCK_AS_MUTEX
typedef pthread_mutex_t pthread_spinlock_t; typedef pthread_mutex_t pthread_spinlock_t;
#endif #endif
#endif
typedef pthread_t TdThread; typedef pthread_t TdThread;
typedef pthread_spinlock_t TdThreadSpinlock; typedef pthread_spinlock_t TdThreadSpinlock;
...@@ -41,6 +44,13 @@ typedef pthread_key_t TdThreadKey; ...@@ -41,6 +44,13 @@ typedef pthread_key_t TdThreadKey;
#define taosThreadCleanupPush pthread_cleanup_push #define taosThreadCleanupPush pthread_cleanup_push
#define taosThreadCleanupPop pthread_cleanup_pop #define taosThreadCleanupPop pthread_cleanup_pop
#ifdef WINDOWS
#define TD_PTHREAD_MUTEX_INITIALIZER (TdThreadMutex)(-1)
#else
#define TD_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#endif
// If the error is in a third-party library, place this header file under the third-party library header file. // If the error is in a third-party library, place this header file under the third-party library header file.
// When you want to use this feature, you should find or add the same function in the following section. // When you want to use this feature, you should find or add the same function in the following section.
#ifndef ALLOW_FORBID_FUNC #ifndef ALLOW_FORBID_FUNC
...@@ -218,8 +228,7 @@ int32_t taosThreadSpinLock(TdThreadSpinlock * lock); ...@@ -218,8 +228,7 @@ int32_t taosThreadSpinLock(TdThreadSpinlock * lock);
int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock); int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock);
int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock); int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock);
void taosThreadTestCancel(void); void taosThreadTestCancel(void);
int32_t taosThreadSigMask(int32_t how, sigset_t const *set, sigset_t * oset); void taosThreadClear(TdThread *thread);
int32_t taosThreadSigWait(const sigset_t * set, int32_t *sig);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
extern "C" { extern "C" {
#endif #endif
#include <time.h>
// If the error is in a third-party library, place this header file under the third-party library header file. // If the error is in a third-party library, place this header file under the third-party library header file.
// When you want to use this feature, you should find or add the same function in the following section. // When you want to use this feature, you should find or add the same function in the following section.
#ifndef ALLOW_FORBID_FUNC #ifndef ALLOW_FORBID_FUNC
...@@ -34,7 +32,7 @@ extern "C" { ...@@ -34,7 +32,7 @@ extern "C" {
#define mktime MKTIME_FUNC_TAOS_FORBID #define mktime MKTIME_FUNC_TAOS_FORBID
#endif #endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#define CLOCK_REALTIME 0 #define CLOCK_REALTIME 0
...@@ -58,6 +56,8 @@ extern "C" { ...@@ -58,6 +56,8 @@ extern "C" {
int32_t taosGetTimeOfDay(struct timeval *tv); int32_t taosGetTimeOfDay(struct timeval *tv);
int32_t taosClockGetTime(int clock_id, struct timespec *pTS);
//@return timestamp in second //@return timestamp in second
int32_t taosGetTimestampSec(); int32_t taosGetTimestampSec();
...@@ -78,7 +78,7 @@ static FORCE_INLINE int64_t taosGetTimestampUs() { ...@@ -78,7 +78,7 @@ static FORCE_INLINE int64_t taosGetTimestampUs() {
//@return timestamp in nanosecond //@return timestamp in nanosecond
static FORCE_INLINE int64_t taosGetTimestampNs() { static FORCE_INLINE int64_t taosGetTimestampNs() {
struct timespec systemTime = {0}; struct timespec systemTime = {0};
clock_gettime(CLOCK_REALTIME, &systemTime); taosClockGetTime(CLOCK_REALTIME, &systemTime);
return (int64_t)systemTime.tv_sec * 1000000000L + (int64_t)systemTime.tv_nsec; return (int64_t)systemTime.tv_sec * 1000000000L + (int64_t)systemTime.tv_nsec;
} }
......
...@@ -236,7 +236,8 @@ static FORCE_INLINE int32_t tEncodeFloat(SCoder* pEncoder, float val) { ...@@ -236,7 +236,8 @@ static FORCE_INLINE int32_t tEncodeFloat(SCoder* pEncoder, float val) {
union { union {
uint32_t ui; uint32_t ui;
float f; float f;
} v = {.f = val}; } v;
v.f = val;
return tEncodeU32(pEncoder, v.ui); return tEncodeU32(pEncoder, v.ui);
} }
...@@ -245,7 +246,8 @@ static FORCE_INLINE int32_t tEncodeDouble(SCoder* pEncoder, double val) { ...@@ -245,7 +246,8 @@ static FORCE_INLINE int32_t tEncodeDouble(SCoder* pEncoder, double val) {
union { union {
uint64_t ui; uint64_t ui;
double d; double d;
} v = {.d = val}; } v;
v.d = val;
return tEncodeU64(pEncoder, v.ui); return tEncodeU64(pEncoder, v.ui);
} }
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
extern "C" { extern "C" {
#endif #endif
#ifdef WINDOWS
#define tjsonGetNumberValue(pJson, pName, val) -1
#else
#define tjsonGetNumberValue(pJson, pName, val) \ #define tjsonGetNumberValue(pJson, pName, val) \
({ \ ({ \
uint64_t _tmp = 0; \ uint64_t _tmp = 0; \
...@@ -29,6 +32,7 @@ extern "C" { ...@@ -29,6 +32,7 @@ extern "C" {
val = _tmp; \ val = _tmp; \
_code; \ _code; \
}) })
#endif
typedef void SJson; typedef void SJson;
......
...@@ -5,8 +5,8 @@ target_include_directories( ...@@ -5,8 +5,8 @@ target_include_directories(
PUBLIC "${TD_SOURCE_DIR}/include/common" PUBLIC "${TD_SOURCE_DIR}/include/common"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
IF(${TD_WINDOWS}) IF(${TD_WINDOWS})
PRIVATE "${TD_SOURCE_DIR}/contrib/pthread-win32" PRIVATE "${TD_SOURCE_DIR}/contrib/pthread"
PRIVATE "${TD_SOURCE_DIR}/contrib/gnuregex" PRIVATE "${TD_SOURCE_DIR}/contrib/msvcregex"
ENDIF () ENDIF ()
) )
target_link_libraries( target_link_libraries(
......
...@@ -167,7 +167,7 @@ TEST(testCase, Datablock_test) { ...@@ -167,7 +167,7 @@ TEST(testCase, Datablock_test) {
printf("the second row of binary:%s, length:%d\n", (char*)varDataVal(pData), varDataLen(pData)); printf("the second row of binary:%s, length:%d\n", (char*)varDataVal(pData), varDataLen(pData));
SArray* pOrderInfo = taosArrayInit(3, sizeof(SBlockOrderInfo)); SArray* pOrderInfo = taosArrayInit(3, sizeof(SBlockOrderInfo));
SBlockOrderInfo order = {.nullFirst = true, .order = TSDB_ORDER_ASC, .slotId = 0}; SBlockOrderInfo order = { true, TSDB_ORDER_ASC, 0, NULL };
taosArrayPush(pOrderInfo, &order); taosArrayPush(pOrderInfo, &order);
blockDataSort(b, pOrderInfo); blockDataSort(b, pOrderInfo);
......
...@@ -40,10 +40,12 @@ static void dmSetSignalHandle() { ...@@ -40,10 +40,12 @@ static void dmSetSignalHandle() {
taosSetSignal(SIGTERM, dmStopDnode); taosSetSignal(SIGTERM, dmStopDnode);
taosSetSignal(SIGHUP, dmStopDnode); taosSetSignal(SIGHUP, dmStopDnode);
taosSetSignal(SIGINT, dmStopDnode); taosSetSignal(SIGINT, dmStopDnode);
taosSetSignal(SIGTSTP, dmStopDnode);
taosSetSignal(SIGABRT, dmStopDnode); taosSetSignal(SIGABRT, dmStopDnode);
taosSetSignal(SIGBREAK, dmStopDnode); taosSetSignal(SIGBREAK, dmStopDnode);
#ifndef WINDOWS
taosSetSignal(SIGTSTP, dmStopDnode);
taosSetSignal(SIGQUIT, dmStopDnode); taosSetSignal(SIGQUIT, dmStopDnode);
#endif
if (!tsMultiProcess) { if (!tsMultiProcess) {
} else if (global.ntype == DNODE || global.ntype == NODE_END) { } else if (global.ntype == DNODE || global.ntype == NODE_END) {
......
...@@ -23,6 +23,9 @@ struct SMetaIdx { ...@@ -23,6 +23,9 @@ struct SMetaIdx {
SIndex *pIdx; SIndex *pIdx;
#endif #endif
/* data */ /* data */
#ifdef WINDOWS
size_t avoidCompilationErrors;
#endif
}; };
int metaOpenIdx(SMeta *pMeta) { int metaOpenIdx(SMeta *pMeta) {
......
...@@ -45,10 +45,12 @@ struct SMetaDB { ...@@ -45,10 +45,12 @@ struct SMetaDB {
#endif #endif
}; };
typedef struct __attribute__((__packed__)) { #pragma pack(push,1)
typedef struct {
tb_uid_t uid; tb_uid_t uid;
int32_t sver; int32_t sver;
} SSchemaDbKey; } SSchemaDbKey;
#pragma pack(pop)
typedef struct { typedef struct {
char *name; char *name;
......
...@@ -86,7 +86,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F ...@@ -86,7 +86,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F
} }
strcpy(pMeta->dirPath, path); strcpy(pMeta->dirPath, path);
char name[pathLen + 10]; char *name = taosMemoryMalloc(pathLen + 10) ;
strcpy(name, path); strcpy(name, path);
if (!taosDirExist(name) && taosMkDir(name) != 0) { if (!taosDirExist(name) && taosMkDir(name) != 0) {
...@@ -99,6 +99,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F ...@@ -99,6 +99,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
tqError("failed to open file:%s since %s ", name, terrstr()); tqError("failed to open file:%s since %s ", name, terrstr());
// free memory // free memory
taosMemoryFree(name);
return NULL; return NULL;
} }
...@@ -106,6 +107,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F ...@@ -106,6 +107,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F
pMeta->unpersistHead = taosMemoryCalloc(1, sizeof(STqMetaList)); pMeta->unpersistHead = taosMemoryCalloc(1, sizeof(STqMetaList));
if (pMeta->unpersistHead == NULL) { if (pMeta->unpersistHead == NULL) {
terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
taosMemoryFree(name);
return NULL; return NULL;
} }
pMeta->unpersistHead->unpersistNext = pMeta->unpersistHead->unpersistPrev = pMeta->unpersistHead; pMeta->unpersistHead->unpersistNext = pMeta->unpersistHead->unpersistPrev = pMeta->unpersistHead;
...@@ -116,8 +118,10 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F ...@@ -116,8 +118,10 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F
if (pFile == NULL) { if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
tqError("failed to open file:%s since %s", name, terrstr()); tqError("failed to open file:%s since %s", name, terrstr());
taosMemoryFree(name);
return NULL; return NULL;
} }
taosMemoryFree(name);
pMeta->pFile = pFile; pMeta->pFile = pFile;
......
...@@ -104,6 +104,10 @@ typedef struct SCatalog { ...@@ -104,6 +104,10 @@ typedef struct SCatalog {
typedef struct SCtgApiStat { typedef struct SCtgApiStat {
#ifdef WINDOWS
size_t avoidCompilationErrors;
#endif
} SCtgApiStat; } SCtgApiStat;
typedef struct SCtgRuntimeStat { typedef struct SCtgRuntimeStat {
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
#pragma GCC diagnostic ignored "-Wformat" #pragma GCC diagnostic ignored "-Wformat"
#include <addr_any.h> #include <addr_any.h>
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "os.h" #include "os.h"
#include "tglobal.h" #include "tglobal.h"
#include "catalog.h" #include "catalog.h"
...@@ -155,11 +158,11 @@ int32_t ctgTestGetVgNumFromVgVersion(int32_t vgVersion) { ...@@ -155,11 +158,11 @@ int32_t ctgTestGetVgNumFromVgVersion(int32_t vgVersion) {
} }
void ctgTestBuildCTableMetaOutput(STableMetaOutput *output) { void ctgTestBuildCTableMetaOutput(STableMetaOutput *output) {
SName cn = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName cn = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(cn.dbname, "db1"); strcpy(cn.dbname, "db1");
strcpy(cn.tname, ctgTestCTablename); strcpy(cn.tname, ctgTestCTablename);
SName sn = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName sn = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(sn.dbname, "db1"); strcpy(sn.dbname, "db1");
strcpy(sn.tname, ctgTestSTablename); strcpy(sn.tname, ctgTestSTablename);
...@@ -577,9 +580,16 @@ void ctgTestSetRspDbVgroups() { ...@@ -577,9 +580,16 @@ void ctgTestSetRspDbVgroups() {
static Stub stub; static Stub stub;
stub.set(rpcSendRecv, ctgTestRspDbVgroups); stub.set(rpcSendRecv, ctgTestRspDbVgroups);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string, void *> result; std::map<std::string, void *> result;
any.get_global_func_addr_dynsym("^rpcSendRecv$", result); any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
#endif
for (const auto &f : result) { for (const auto &f : result) {
stub.set(f.second, ctgTestRspDbVgroups); stub.set(f.second, ctgTestRspDbVgroups);
} }
...@@ -590,9 +600,16 @@ void ctgTestSetRspTableMeta() { ...@@ -590,9 +600,16 @@ void ctgTestSetRspTableMeta() {
static Stub stub; static Stub stub;
stub.set(rpcSendRecv, ctgTestRspTableMeta); stub.set(rpcSendRecv, ctgTestRspTableMeta);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string, void *> result; std::map<std::string, void *> result;
any.get_global_func_addr_dynsym("^rpcSendRecv$", result); any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
#endif
for (const auto &f : result) { for (const auto &f : result) {
stub.set(f.second, ctgTestRspTableMeta); stub.set(f.second, ctgTestRspTableMeta);
} }
...@@ -603,9 +620,16 @@ void ctgTestSetRspCTableMeta() { ...@@ -603,9 +620,16 @@ void ctgTestSetRspCTableMeta() {
static Stub stub; static Stub stub;
stub.set(rpcSendRecv, ctgTestRspCTableMeta); stub.set(rpcSendRecv, ctgTestRspCTableMeta);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string, void *> result; std::map<std::string, void *> result;
any.get_global_func_addr_dynsym("^rpcSendRecv$", result); any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
#endif
for (const auto &f : result) { for (const auto &f : result) {
stub.set(f.second, ctgTestRspCTableMeta); stub.set(f.second, ctgTestRspCTableMeta);
} }
...@@ -616,9 +640,16 @@ void ctgTestSetRspSTableMeta() { ...@@ -616,9 +640,16 @@ void ctgTestSetRspSTableMeta() {
static Stub stub; static Stub stub;
stub.set(rpcSendRecv, ctgTestRspSTableMeta); stub.set(rpcSendRecv, ctgTestRspSTableMeta);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string, void *> result; std::map<std::string, void *> result;
any.get_global_func_addr_dynsym("^rpcSendRecv$", result); any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
#endif
for (const auto &f : result) { for (const auto &f : result) {
stub.set(f.second, ctgTestRspSTableMeta); stub.set(f.second, ctgTestRspSTableMeta);
} }
...@@ -629,9 +660,16 @@ void ctgTestSetRspMultiSTableMeta() { ...@@ -629,9 +660,16 @@ void ctgTestSetRspMultiSTableMeta() {
static Stub stub; static Stub stub;
stub.set(rpcSendRecv, ctgTestRspMultiSTableMeta); stub.set(rpcSendRecv, ctgTestRspMultiSTableMeta);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string, void *> result; std::map<std::string, void *> result;
any.get_global_func_addr_dynsym("^rpcSendRecv$", result); any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
#endif
for (const auto &f : result) { for (const auto &f : result) {
stub.set(f.second, ctgTestRspMultiSTableMeta); stub.set(f.second, ctgTestRspMultiSTableMeta);
} }
...@@ -642,9 +680,16 @@ void ctgTestSetRspByIdx() { ...@@ -642,9 +680,16 @@ void ctgTestSetRspByIdx() {
static Stub stub; static Stub stub;
stub.set(rpcSendRecv, ctgTestRspByIdx); stub.set(rpcSendRecv, ctgTestRspByIdx);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string, void *> result; std::map<std::string, void *> result;
any.get_global_func_addr_dynsym("^rpcSendRecv$", result); any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
#endif
for (const auto &f : result) { for (const auto &f : result) {
stub.set(f.second, ctgTestRspByIdx); stub.set(f.second, ctgTestRspByIdx);
} }
...@@ -656,9 +701,16 @@ void ctgTestSetRspDbVgroupsAndNormalMeta() { ...@@ -656,9 +701,16 @@ void ctgTestSetRspDbVgroupsAndNormalMeta() {
static Stub stub; static Stub stub;
stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndNormalMeta); stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndNormalMeta);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string, void *> result; std::map<std::string, void *> result;
any.get_global_func_addr_dynsym("^rpcSendRecv$", result); any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
#endif
for (const auto &f : result) { for (const auto &f : result) {
stub.set(f.second, ctgTestRspDbVgroupsAndNormalMeta); stub.set(f.second, ctgTestRspDbVgroupsAndNormalMeta);
} }
...@@ -669,9 +721,16 @@ void ctgTestSetRspDbVgroupsAndChildMeta() { ...@@ -669,9 +721,16 @@ void ctgTestSetRspDbVgroupsAndChildMeta() {
static Stub stub; static Stub stub;
stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndChildMeta); stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndChildMeta);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string, void *> result; std::map<std::string, void *> result;
any.get_global_func_addr_dynsym("^rpcSendRecv$", result); any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
#endif
for (const auto &f : result) { for (const auto &f : result) {
stub.set(f.second, ctgTestRspDbVgroupsAndChildMeta); stub.set(f.second, ctgTestRspDbVgroupsAndChildMeta);
} }
...@@ -682,9 +741,16 @@ void ctgTestSetRspDbVgroupsAndSuperMeta() { ...@@ -682,9 +741,16 @@ void ctgTestSetRspDbVgroupsAndSuperMeta() {
static Stub stub; static Stub stub;
stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndSuperMeta); stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndSuperMeta);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string, void *> result; std::map<std::string, void *> result;
any.get_global_func_addr_dynsym("^rpcSendRecv$", result); any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
#endif
for (const auto &f : result) { for (const auto &f : result) {
stub.set(f.second, ctgTestRspDbVgroupsAndSuperMeta); stub.set(f.second, ctgTestRspDbVgroupsAndSuperMeta);
} }
...@@ -695,9 +761,16 @@ void ctgTestSetRspDbVgroupsAndMultiSuperMeta() { ...@@ -695,9 +761,16 @@ void ctgTestSetRspDbVgroupsAndMultiSuperMeta() {
static Stub stub; static Stub stub;
stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndMultiSuperMeta); stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndMultiSuperMeta);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string, void *> result; std::map<std::string, void *> result;
any.get_global_func_addr_dynsym("^rpcSendRecv$", result); any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
#endif
for (const auto &f : result) { for (const auto &f : result) {
stub.set(f.second, ctgTestRspDbVgroupsAndMultiSuperMeta); stub.set(f.second, ctgTestRspDbVgroupsAndMultiSuperMeta);
} }
...@@ -789,7 +862,7 @@ void *ctgTestGetCtableMetaThread(void *param) { ...@@ -789,7 +862,7 @@ void *ctgTestGetCtableMetaThread(void *param) {
STableMeta *tbMeta = NULL; STableMeta *tbMeta = NULL;
bool inCache = false; bool inCache = false;
SName cn = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName cn = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(cn.dbname, "db1"); strcpy(cn.dbname, "db1");
strcpy(cn.tname, ctgTestCTablename); strcpy(cn.tname, ctgTestCTablename);
...@@ -871,7 +944,7 @@ TEST(tableMeta, normalTable) { ...@@ -871,7 +944,7 @@ TEST(tableMeta, normalTable) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestTablename); strcpy(n.tname, ctgTestTablename);
...@@ -978,7 +1051,7 @@ TEST(tableMeta, childTableCase) { ...@@ -978,7 +1051,7 @@ TEST(tableMeta, childTableCase) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestCTablename); strcpy(n.tname, ctgTestCTablename);
...@@ -1085,7 +1158,7 @@ TEST(tableMeta, superTableCase) { ...@@ -1085,7 +1158,7 @@ TEST(tableMeta, superTableCase) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestSTablename); strcpy(n.tname, ctgTestSTablename);
...@@ -1210,7 +1283,7 @@ TEST(tableMeta, rmStbMeta) { ...@@ -1210,7 +1283,7 @@ TEST(tableMeta, rmStbMeta) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestSTablename); strcpy(n.tname, ctgTestSTablename);
...@@ -1280,7 +1353,7 @@ TEST(tableMeta, updateStbMeta) { ...@@ -1280,7 +1353,7 @@ TEST(tableMeta, updateStbMeta) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestSTablename); strcpy(n.tname, ctgTestSTablename);
...@@ -1378,7 +1451,7 @@ TEST(refreshGetMeta, normal2normal) { ...@@ -1378,7 +1451,7 @@ TEST(refreshGetMeta, normal2normal) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestTablename); strcpy(n.tname, ctgTestTablename);
...@@ -1457,7 +1530,7 @@ TEST(refreshGetMeta, normal2notexist) { ...@@ -1457,7 +1530,7 @@ TEST(refreshGetMeta, normal2notexist) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestTablename); strcpy(n.tname, ctgTestTablename);
...@@ -1529,7 +1602,7 @@ TEST(refreshGetMeta, normal2child) { ...@@ -1529,7 +1602,7 @@ TEST(refreshGetMeta, normal2child) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestTablename); strcpy(n.tname, ctgTestTablename);
ctgTestCurrentCTableName = ctgTestTablename; ctgTestCurrentCTableName = ctgTestTablename;
...@@ -1613,7 +1686,7 @@ TEST(refreshGetMeta, stable2child) { ...@@ -1613,7 +1686,7 @@ TEST(refreshGetMeta, stable2child) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestTablename); strcpy(n.tname, ctgTestTablename);
ctgTestCurrentSTableName = ctgTestTablename; ctgTestCurrentSTableName = ctgTestTablename;
...@@ -1699,7 +1772,7 @@ TEST(refreshGetMeta, stable2stable) { ...@@ -1699,7 +1772,7 @@ TEST(refreshGetMeta, stable2stable) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestTablename); strcpy(n.tname, ctgTestTablename);
ctgTestCurrentSTableName = ctgTestTablename; ctgTestCurrentSTableName = ctgTestTablename;
...@@ -1786,7 +1859,7 @@ TEST(refreshGetMeta, child2stable) { ...@@ -1786,7 +1859,7 @@ TEST(refreshGetMeta, child2stable) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestTablename); strcpy(n.tname, ctgTestTablename);
ctgTestCurrentCTableName = ctgTestTablename; ctgTestCurrentCTableName = ctgTestTablename;
...@@ -1871,7 +1944,7 @@ TEST(tableDistVgroup, normalTable) { ...@@ -1871,7 +1944,7 @@ TEST(tableDistVgroup, normalTable) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestTablename); strcpy(n.tname, ctgTestTablename);
...@@ -1913,7 +1986,7 @@ TEST(tableDistVgroup, childTableCase) { ...@@ -1913,7 +1986,7 @@ TEST(tableDistVgroup, childTableCase) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestCTablename); strcpy(n.tname, ctgTestCTablename);
...@@ -1956,7 +2029,7 @@ TEST(tableDistVgroup, superTableCase) { ...@@ -1956,7 +2029,7 @@ TEST(tableDistVgroup, superTableCase) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestSTablename); strcpy(n.tname, ctgTestSTablename);
...@@ -2006,7 +2079,7 @@ TEST(dbVgroup, getSetDbVgroupCase) { ...@@ -2006,7 +2079,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestTablename); strcpy(n.tname, ctgTestTablename);
...@@ -2091,7 +2164,7 @@ TEST(multiThread, getSetRmSameDbVgroup) { ...@@ -2091,7 +2164,7 @@ TEST(multiThread, getSetRmSameDbVgroup) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestTablename); strcpy(n.tname, ctgTestTablename);
...@@ -2143,7 +2216,7 @@ TEST(multiThread, getSetRmDiffDbVgroup) { ...@@ -2143,7 +2216,7 @@ TEST(multiThread, getSetRmDiffDbVgroup) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestTablename); strcpy(n.tname, ctgTestTablename);
...@@ -2195,7 +2268,7 @@ TEST(multiThread, ctableMeta) { ...@@ -2195,7 +2268,7 @@ TEST(multiThread, ctableMeta) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
strcpy(n.tname, ctgTestTablename); strcpy(n.tname, ctgTestTablename);
...@@ -2247,7 +2320,7 @@ TEST(rentTest, allRent) { ...@@ -2247,7 +2320,7 @@ TEST(rentTest, allRent) {
code = catalogGetHandle(ctgTestClusterId, &pCtg); code = catalogGetHandle(ctgTestClusterId, &pCtg);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} };
strcpy(n.dbname, "db1"); strcpy(n.dbname, "db1");
for (int32_t i = 1; i <= 10; ++i) { for (int32_t i = 1; i <= 10; ++i) {
......
...@@ -410,8 +410,8 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) { ...@@ -410,8 +410,8 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
int32_t contentLen = 0; int32_t contentLen = 0;
if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
int32_t* offset = pPage + startOffset; int32_t* offset = (int32_t*)((char*)pPage + startOffset);
columnLen = pPage + startOffset + sizeof(int32_t) * pInfo->rowCapacity; columnLen = (char*)pPage + startOffset + sizeof(int32_t) * pInfo->rowCapacity;
char* data = (char*)(columnLen + sizeof(int32_t)); char* data = (char*)(columnLen + sizeof(int32_t));
if (colDataIsNull_s(pColInfoData, j)) { if (colDataIsNull_s(pColInfoData, j)) {
...@@ -424,8 +424,8 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) { ...@@ -424,8 +424,8 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
contentLen = varDataTLen(src); contentLen = varDataTLen(src);
} }
} else { } else {
char* bitmap = pPage + startOffset; char* bitmap = (char*)pPage + startOffset;
columnLen = pPage + startOffset + BitmapLen(pInfo->rowCapacity); columnLen = (char*)pPage + startOffset + BitmapLen(pInfo->rowCapacity);
char* data = (char*) columnLen + sizeof(int32_t); char* data = (char*) columnLen + sizeof(int32_t);
bool isNull = colDataIsNull_f(pColInfoData->nullbitmap, j); bool isNull = colDataIsNull_f(pColInfoData->nullbitmap, j);
......
...@@ -48,7 +48,7 @@ struct SSHashObj { ...@@ -48,7 +48,7 @@ struct SSHashObj {
}; };
static FORCE_INLINE int32_t taosHashCapacity(int32_t length) { static FORCE_INLINE int32_t taosHashCapacity(int32_t length) {
int32_t len = MIN(length, HASH_MAX_CAPACITY); int32_t len = (length < HASH_MAX_CAPACITY ? length : HASH_MAX_CAPACITY);
int32_t i = 4; int32_t i = 4;
while (i < len) i = (i << 1u); while (i < len) i = (i << 1u);
...@@ -127,7 +127,7 @@ static void taosHashTableResize(SSHashObj *pHashObj) { ...@@ -127,7 +127,7 @@ static void taosHashTableResize(SSHashObj *pHashObj) {
} }
size_t inc = newCapacity - pHashObj->capacity; size_t inc = newCapacity - pHashObj->capacity;
memset(pNewEntryList + pHashObj->capacity * sizeof(void*), 0, inc); memset((char*)pNewEntryList + pHashObj->capacity * sizeof(void*), 0, inc);
pHashObj->hashList = pNewEntryList; pHashObj->hashList = pNewEntryList;
pHashObj->capacity = newCapacity; pHashObj->capacity = newCapacity;
...@@ -301,7 +301,7 @@ size_t tSimpleHashGetMemSize(const SSHashObj *pHashObj) { ...@@ -301,7 +301,7 @@ size_t tSimpleHashGetMemSize(const SSHashObj *pHashObj) {
void *tSimpleHashGetKey(const SSHashObj* pHashObj, void *data, size_t* keyLen) { void *tSimpleHashGetKey(const SSHashObj* pHashObj, void *data, size_t* keyLen) {
int32_t offset = offsetof(SHNode, data); int32_t offset = offsetof(SHNode, data);
SHNode *node = data - offset; SHNode *node = ((SHNode*)(char*)data - offset);
if (keyLen != NULL) { if (keyLen != NULL) {
*keyLen = pHashObj->keyLen; *keyLen = pHashObj->keyLen;
} }
......
...@@ -102,7 +102,7 @@ SSDataBlock* getDummyBlock(SOperatorInfo* pOperator, bool* newgroup) { ...@@ -102,7 +102,7 @@ SSDataBlock* getDummyBlock(SOperatorInfo* pOperator, bool* newgroup) {
} else if (pInfo->type == data_asc) { } else if (pInfo->type == data_asc) {
v = ++pInfo->startVal; v = ++pInfo->startVal;
} else if (pInfo->type == data_rand) { } else if (pInfo->type == data_rand) {
v = random(); v = taosRand();
} }
colDataAppend(pColInfo, i, reinterpret_cast<const char*>(&v), false); colDataAppend(pColInfo, i, reinterpret_cast<const char*>(&v), false);
...@@ -172,7 +172,7 @@ SSDataBlock* get2ColsDummyBlock(SOperatorInfo* pOperator, bool* newgroup) { ...@@ -172,7 +172,7 @@ SSDataBlock* get2ColsDummyBlock(SOperatorInfo* pOperator, bool* newgroup) {
} else if (pInfo->type == data_asc) { } else if (pInfo->type == data_asc) {
v = ++pInfo->startVal; v = ++pInfo->startVal;
} else if (pInfo->type == data_rand) { } else if (pInfo->type == data_rand) {
v = random(); v = taosRand();
} }
colDataAppend(pColInfo1, i, reinterpret_cast<const char*>(&v), false); colDataAppend(pColInfo1, i, reinterpret_cast<const char*>(&v), false);
...@@ -938,7 +938,7 @@ TEST(testCase, build_executor_tree_Test) { ...@@ -938,7 +938,7 @@ TEST(testCase, build_executor_tree_Test) {
SExecTaskInfo* pTaskInfo = nullptr; SExecTaskInfo* pTaskInfo = nullptr;
DataSinkHandle sinkHandle = nullptr; DataSinkHandle sinkHandle = nullptr;
SReadHandle handle = {.reader = reinterpret_cast<void*>(0x1), .meta = reinterpret_cast<void*>(0x1)}; SReadHandle handle = { reinterpret_cast<void*>(0x1), reinterpret_cast<void*>(0x1), NULL };
struct SSubplan *plan = NULL; struct SSubplan *plan = NULL;
int32_t code = qStringToSubplan(msg, &plan); int32_t code = qStringToSubplan(msg, &plan);
......
...@@ -47,6 +47,9 @@ target_include_directories( ...@@ -47,6 +47,9 @@ target_include_directories(
"${TD_SOURCE_DIR}/include/os" "${TD_SOURCE_DIR}/include/os"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
) )
target_link_libraries(
udf1 PUBLIC os
)
#SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build/bin) #SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build/bin)
add_executable(udfd src/udfd.c) add_executable(udfd src/udfd.c)
......
...@@ -69,6 +69,9 @@ typedef struct SUdfTeardownRequest { ...@@ -69,6 +69,9 @@ typedef struct SUdfTeardownRequest {
typedef struct SUdfTeardownResponse { typedef struct SUdfTeardownResponse {
#ifdef WINDOWS
size_t avoidCompilationErrors;
#endif
} SUdfTeardownResponse; } SUdfTeardownResponse;
typedef struct SUdfRequest { typedef struct SUdfRequest {
......
...@@ -84,6 +84,9 @@ typedef struct SUdfTeardownRequest { ...@@ -84,6 +84,9 @@ typedef struct SUdfTeardownRequest {
typedef struct SUdfTeardownResponse { typedef struct SUdfTeardownResponse {
#ifdef WINDOWS
size_t avoidCompilationErrors;
#endif
} SUdfTeardownResponse; } SUdfTeardownResponse;
typedef struct SUdfRequest { typedef struct SUdfRequest {
......
...@@ -31,6 +31,9 @@ extern "C" { ...@@ -31,6 +31,9 @@ extern "C" {
typedef enum { MATCH, JUMP, SPLIT, RANGE } InstType; typedef enum { MATCH, JUMP, SPLIT, RANGE } InstType;
typedef struct MatchValue { typedef struct MatchValue {
#ifdef WINDOWS
size_t avoidCompilationErrors;
#endif
} MatchValue; } MatchValue;
typedef struct JumpValue { typedef struct JumpValue {
uint32_t step; uint32_t step;
......
...@@ -748,7 +748,7 @@ static SArray* tfileGetFileList(const char* path) { ...@@ -748,7 +748,7 @@ static SArray* tfileGetFileList(const char* path) {
sprintf(buf, "%s/%s", path, file); sprintf(buf, "%s/%s", path, file);
taosArrayPush(files, &buf); taosArrayPush(files, &buf);
} }
taosCloseDir(pDir); taosCloseDir(&pDir);
taosArraySort(files, tfileCompare); taosArraySort(files, tfileCompare);
tfileRmExpireFile(files); tfileRmExpireFile(files);
......
...@@ -485,7 +485,7 @@ TEST_F(IndexTFileEnv, test_tfile_write) { ...@@ -485,7 +485,7 @@ TEST_F(IndexTFileEnv, test_tfile_write) {
std::string colVal("ab"); std::string colVal("ab");
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
colVal.c_str(), colVal.size()); colVal.c_str(), colVal.size());
SIndexTermQuery query = {.term = term, .qType = QUERY_TERM}; SIndexTermQuery query = { term, QUERY_TERM};
SArray* result = (SArray*)taosArrayInit(1, sizeof(uint64_t)); SArray* result = (SArray*)taosArrayInit(1, sizeof(uint64_t));
fObj->Get(&query, result); fObj->Get(&query, result);
...@@ -625,7 +625,7 @@ TEST_F(IndexCacheEnv, cache_test) { ...@@ -625,7 +625,7 @@ TEST_F(IndexCacheEnv, cache_test) {
std::string colVal("v3"); std::string colVal("v3");
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
colVal.c_str(), colVal.size()); colVal.c_str(), colVal.size());
SIndexTermQuery query = {.term = term, .qType = QUERY_TERM}; SIndexTermQuery query = { term, QUERY_TERM };
SArray* ret = (SArray*)taosArrayInit(4, sizeof(suid)); SArray* ret = (SArray*)taosArrayInit(4, sizeof(suid));
STermValueType valType; STermValueType valType;
...@@ -640,7 +640,7 @@ TEST_F(IndexCacheEnv, cache_test) { ...@@ -640,7 +640,7 @@ TEST_F(IndexCacheEnv, cache_test) {
std::string colVal("v2"); std::string colVal("v2");
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
colVal.c_str(), colVal.size()); colVal.c_str(), colVal.size());
SIndexTermQuery query = {.term = term, .qType = QUERY_TERM}; SIndexTermQuery query = { term, QUERY_TERM };
SArray* ret = (SArray*)taosArrayInit(4, sizeof(suid)); SArray* ret = (SArray*)taosArrayInit(4, sizeof(suid));
STermValueType valType; STermValueType valType;
......
...@@ -108,7 +108,7 @@ TEST_F(JsonEnv, testWriteMillonData) { ...@@ -108,7 +108,7 @@ TEST_F(JsonEnv, testWriteMillonData) {
{ {
std::string colName("voltagefdadfa"); std::string colName("voltagefdadfa");
std::string colVal("abxxxxxxxxxxxx"); std::string colVal("abxxxxxxxxxxxx");
for (uint i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
colVal[i % colVal.size()] = '0' + i % 128; colVal[i % colVal.size()] = '0' + i % 128;
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
colVal.c_str(), colVal.size()); colVal.c_str(), colVal.size());
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
extern "C" { extern "C" {
#endif #endif
#include "os.h"
#include "ttokendef.h" #include "ttokendef.h"
// used to denote the minimum unite in sql parsing // used to denote the minimum unite in sql parsing
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h"
#include "parInt.h" #include "parInt.h"
#include "parAst.h" #include "parAst.h"
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h"
#include "parInsertData.h" #include "parInsertData.h"
#include "parInt.h" #include "parInt.h"
#include "parToken.h" #include "parToken.h"
......
...@@ -49,12 +49,14 @@ static bool afterGroupBy(ESqlClause clause) { return clause > SQL_CLAUSE_GROUP_B ...@@ -49,12 +49,14 @@ static bool afterGroupBy(ESqlClause clause) { return clause > SQL_CLAUSE_GROUP_B
static bool beforeHaving(ESqlClause clause) { return clause < SQL_CLAUSE_HAVING; } static bool beforeHaving(ESqlClause clause) { return clause < SQL_CLAUSE_HAVING; }
#define generateDealNodeErrMsg(pCxt, code, ...) \ enum EDealRes generateDealNodeErrMsg(STranslateContext* pCxt, int32_t code, ...) {
({ \ va_list ap;
generateSyntaxErrMsg(&pCxt->msgBuf, code, ##__VA_ARGS__); \ va_start(ap, code);
pCxt->errCode = code; \ generateSyntaxErrMsg(&pCxt->msgBuf, code, ap);
DEAL_RES_ERROR; \ va_end(ap);
}) pCxt->errCode = code;
return DEAL_RES_ERROR;
}
static int32_t addNamespace(STranslateContext* pCxt, void* pTable) { static int32_t addNamespace(STranslateContext* pCxt, void* pTable) {
size_t currTotalLevel = taosArrayGetSize(pCxt->pNsLevel); size_t currTotalLevel = taosArrayGetSize(pCxt->pNsLevel);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h"
#include "parser.h" #include "parser.h"
#include "parInt.h" #include "parInt.h"
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include "os.h"
#include "functionMgt.h" #include "functionMgt.h"
#include "nodes.h" #include "nodes.h"
#include "parToken.h" #include "parToken.h"
......
...@@ -17,3 +17,11 @@ TARGET_LINK_LIBRARIES( ...@@ -17,3 +17,11 @@ TARGET_LINK_LIBRARIES(
parserTest parserTest
PUBLIC os util common nodes parser catalog transport gtest function planner qcom PUBLIC os util common nodes parser catalog transport gtest function planner qcom
) )
if(${BUILD_WINGETOPT})
target_include_directories(
parserTest
PUBLIC "${TD_SOURCE_DIR}/contrib/wingetopt/src"
)
target_link_libraries(parserTest PUBLIC wingetopt)
endif()
\ No newline at end of file
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <iostream> #include <iostream>
#include "stub.h" #include "stub.h"
...@@ -23,6 +22,9 @@ ...@@ -23,6 +22,9 @@
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "mockCatalog.h" #include "mockCatalog.h"
namespace { namespace {
......
...@@ -40,13 +40,11 @@ public: ...@@ -40,13 +40,11 @@ public:
virtual TableBuilder& setVgid(int16_t vgid) { virtual TableBuilder& setVgid(int16_t vgid) {
schema()->vgId = vgid; schema()->vgId = vgid;
SVgroupInfo vgroup = {.vgId = vgid, .hashBegin = 0, .hashEnd = 0, }; SVgroupInfo vgroup = { vgid, 0, 0, {0}, 0};
addEpIntoEpSet(&vgroup.epSet, "dnode_1", 6030);
vgroup.epSet.eps[0] = (SEp){"dnode_1", 6030}; addEpIntoEpSet(&vgroup.epSet, "dnode_2", 6030);
vgroup.epSet.eps[1] = (SEp){"dnode_2", 6030}; addEpIntoEpSet(&vgroup.epSet, "dnode_3", 6030);
vgroup.epSet.eps[2] = (SEp){"dnode_3", 6030};
vgroup.epSet.inUse = 0; vgroup.epSet.inUse = 0;
vgroup.epSet.numOfEps = 3;
meta_->vgs.emplace_back(vgroup); meta_->vgs.emplace_back(vgroup);
return *this; return *this;
...@@ -148,7 +146,7 @@ public: ...@@ -148,7 +146,7 @@ public:
meta_[db][tbname]->schema->uid = id_++; meta_[db][tbname]->schema->uid = id_++;
meta_[db][tbname]->schema->tableType = TSDB_CHILD_TABLE; meta_[db][tbname]->schema->tableType = TSDB_CHILD_TABLE;
SVgroupInfo vgroup = {.vgId = vgid, .hashBegin = 0, .hashEnd = 0,}; SVgroupInfo vgroup = { vgid, 0, 0, {0}, 0};
addEpIntoEpSet(&vgroup.epSet, "dnode_1", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_1", 6030);
addEpIntoEpSet(&vgroup.epSet, "dnode_2", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_2", 6030);
addEpIntoEpSet(&vgroup.epSet, "dnode_3", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_3", 6030);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "os.h"
#include "parInt.h" #include "parInt.h"
using namespace std; using namespace std;
......
...@@ -14,14 +14,20 @@ ...@@ -14,14 +14,20 @@
*/ */
#include <string> #include <string>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h> #include <getopt.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "mockCatalog.h" #ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "os.h"
#include "parserTestUtil.h" #include "parserTestUtil.h"
#include "parToken.h" #include "parToken.h"
#include "functionMgt.h" #include "functionMgt.h"
#include "mockCatalog.h"
bool g_isDump = false; bool g_isDump = false;
......
...@@ -22,3 +22,12 @@ TARGET_INCLUDE_DIRECTORIES( ...@@ -22,3 +22,12 @@ TARGET_INCLUDE_DIRECTORIES(
PRIVATE "${TD_SOURCE_DIR}/source/libs/planner/inc" PRIVATE "${TD_SOURCE_DIR}/source/libs/planner/inc"
PRIVATE "${TD_SOURCE_DIR}/source/libs/parser/test" PRIVATE "${TD_SOURCE_DIR}/source/libs/parser/test"
) )
if(${BUILD_WINGETOPT})
target_include_directories(
plannerTest
PUBLIC "${TD_SOURCE_DIR}/contrib/wingetopt/src"
)
target_link_libraries(plannerTest PUBLIC wingetopt)
endif()
\ No newline at end of file
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include <string> #include <string>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "getopt.h"
#include "mockCatalog.h" #include "mockCatalog.h"
#include "planTestUtil.h" #include "planTestUtil.h"
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <array>
#include "planTestUtil.h" #include "planTestUtil.h"
#include <algorithm> #include <algorithm>
......
...@@ -95,6 +95,9 @@ typedef struct SQWPhaseInput { ...@@ -95,6 +95,9 @@ typedef struct SQWPhaseInput {
} SQWPhaseInput; } SQWPhaseInput;
typedef struct SQWPhaseOutput { typedef struct SQWPhaseOutput {
#ifdef WINDOWS
size_t avoidCompilationErrors;
#endif
} SQWPhaseOutput; } SQWPhaseOutput;
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
#pragma GCC diagnostic ignored "-Wpointer-arith" #pragma GCC diagnostic ignored "-Wpointer-arith"
#include <addr_any.h> #include <addr_any.h>
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "os.h" #include "os.h"
#include "tglobal.h" #include "tglobal.h"
...@@ -277,8 +280,8 @@ int32_t qwtCreateExecTask(void* tsdb, int32_t vgId, uint64_t taskId, struct SSub ...@@ -277,8 +280,8 @@ int32_t qwtCreateExecTask(void* tsdb, int32_t vgId, uint64_t taskId, struct SSub
qwtTestSinkMaxBlockNum = taosRand() % 100 + 1; qwtTestSinkMaxBlockNum = taosRand() % 100 + 1;
qwtTestSinkQueryEnd = false; qwtTestSinkQueryEnd = false;
*pTaskInfo = (qTaskInfo_t)qwtTestCaseIdx+1; *pTaskInfo = (qTaskInfo_t)((char*)qwtTestCaseIdx+1);
*handle = (DataSinkHandle)qwtTestCaseIdx+2; *handle = (DataSinkHandle)((char*)qwtTestCaseIdx+2);
++qwtTestCaseIdx; ++qwtTestCaseIdx;
...@@ -435,9 +438,16 @@ void stubSetStringToPlan() { ...@@ -435,9 +438,16 @@ void stubSetStringToPlan() {
static Stub stub; static Stub stub;
stub.set(qStringToSubplan, qwtStringToPlan); stub.set(qStringToSubplan, qwtStringToPlan);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("qStringToSubplan", result);
#endif
#ifdef LINUX
AddrAny any("libplanner.so"); AddrAny any("libplanner.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^qStringToSubplan$", result); any.get_global_func_addr_dynsym("^qStringToSubplan$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, qwtStringToPlan); stub.set(f.second, qwtStringToPlan);
} }
...@@ -448,9 +458,16 @@ void stubSetExecTask() { ...@@ -448,9 +458,16 @@ void stubSetExecTask() {
static Stub stub; static Stub stub;
stub.set(qExecTask, qwtExecTask); stub.set(qExecTask, qwtExecTask);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("qExecTask", result);
#endif
#ifdef LINUX
AddrAny any("libexecutor.so"); AddrAny any("libexecutor.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^qExecTask$", result); any.get_global_func_addr_dynsym("^qExecTask$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, qwtExecTask); stub.set(f.second, qwtExecTask);
} }
...@@ -463,9 +480,16 @@ void stubSetCreateExecTask() { ...@@ -463,9 +480,16 @@ void stubSetCreateExecTask() {
static Stub stub; static Stub stub;
stub.set(qCreateExecTask, qwtCreateExecTask); stub.set(qCreateExecTask, qwtCreateExecTask);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("qCreateExecTask", result);
#endif
#ifdef LINUX
AddrAny any("libexecutor.so"); AddrAny any("libexecutor.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^qCreateExecTask$", result); any.get_global_func_addr_dynsym("^qCreateExecTask$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, qwtCreateExecTask); stub.set(f.second, qwtCreateExecTask);
} }
...@@ -476,9 +500,16 @@ void stubSetAsyncKillTask() { ...@@ -476,9 +500,16 @@ void stubSetAsyncKillTask() {
static Stub stub; static Stub stub;
stub.set(qAsyncKillTask, qwtKillTask); stub.set(qAsyncKillTask, qwtKillTask);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("qAsyncKillTask", result);
#endif
#ifdef LINUX
AddrAny any("libexecutor.so"); AddrAny any("libexecutor.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^qAsyncKillTask$", result); any.get_global_func_addr_dynsym("^qAsyncKillTask$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, qwtKillTask); stub.set(f.second, qwtKillTask);
} }
...@@ -489,9 +520,16 @@ void stubSetDestroyTask() { ...@@ -489,9 +520,16 @@ void stubSetDestroyTask() {
static Stub stub; static Stub stub;
stub.set(qDestroyTask, qwtDestroyTask); stub.set(qDestroyTask, qwtDestroyTask);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("qDestroyTask", result);
#endif
#ifdef LINUX
AddrAny any("libexecutor.so"); AddrAny any("libexecutor.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^qDestroyTask$", result); any.get_global_func_addr_dynsym("^qDestroyTask$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, qwtDestroyTask); stub.set(f.second, qwtDestroyTask);
} }
...@@ -503,9 +541,16 @@ void stubSetDestroyDataSinker() { ...@@ -503,9 +541,16 @@ void stubSetDestroyDataSinker() {
static Stub stub; static Stub stub;
stub.set(dsDestroyDataSinker, qwtDestroyDataSinker); stub.set(dsDestroyDataSinker, qwtDestroyDataSinker);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("dsDestroyDataSinker", result);
#endif
#ifdef LINUX
AddrAny any("libexecutor.so"); AddrAny any("libexecutor.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^dsDestroyDataSinker$", result); any.get_global_func_addr_dynsym("^dsDestroyDataSinker$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, qwtDestroyDataSinker); stub.set(f.second, qwtDestroyDataSinker);
} }
...@@ -516,9 +561,16 @@ void stubSetGetDataLength() { ...@@ -516,9 +561,16 @@ void stubSetGetDataLength() {
static Stub stub; static Stub stub;
stub.set(dsGetDataLength, qwtGetDataLength); stub.set(dsGetDataLength, qwtGetDataLength);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("dsGetDataLength", result);
#endif
#ifdef LINUX
AddrAny any("libexecutor.so"); AddrAny any("libexecutor.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^dsGetDataLength$", result); any.get_global_func_addr_dynsym("^dsGetDataLength$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, qwtGetDataLength); stub.set(f.second, qwtGetDataLength);
} }
...@@ -529,9 +581,16 @@ void stubSetEndPut() { ...@@ -529,9 +581,16 @@ void stubSetEndPut() {
static Stub stub; static Stub stub;
stub.set(dsEndPut, qwtEndPut); stub.set(dsEndPut, qwtEndPut);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("dsEndPut", result);
#endif
#ifdef LINUX
AddrAny any("libexecutor.so"); AddrAny any("libexecutor.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^dsEndPut$", result); any.get_global_func_addr_dynsym("^dsEndPut$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, qwtEndPut); stub.set(f.second, qwtEndPut);
} }
...@@ -542,9 +601,16 @@ void stubSetPutDataBlock() { ...@@ -542,9 +601,16 @@ void stubSetPutDataBlock() {
static Stub stub; static Stub stub;
stub.set(dsPutDataBlock, qwtPutDataBlock); stub.set(dsPutDataBlock, qwtPutDataBlock);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("dsPutDataBlock", result);
#endif
#ifdef LINUX
AddrAny any("libexecutor.so"); AddrAny any("libexecutor.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^dsPutDataBlock$", result); any.get_global_func_addr_dynsym("^dsPutDataBlock$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, qwtPutDataBlock); stub.set(f.second, qwtPutDataBlock);
} }
...@@ -555,9 +621,16 @@ void stubSetRpcSendResponse() { ...@@ -555,9 +621,16 @@ void stubSetRpcSendResponse() {
static Stub stub; static Stub stub;
stub.set(rpcSendResponse, qwtRpcSendResponse); stub.set(rpcSendResponse, qwtRpcSendResponse);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("rpcSendResponse", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^rpcSendResponse$", result); any.get_global_func_addr_dynsym("^rpcSendResponse$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, qwtRpcSendResponse); stub.set(f.second, qwtRpcSendResponse);
} }
...@@ -568,9 +641,16 @@ void stubSetGetDataBlock() { ...@@ -568,9 +641,16 @@ void stubSetGetDataBlock() {
static Stub stub; static Stub stub;
stub.set(dsGetDataBlock, qwtGetDataBlock); stub.set(dsGetDataBlock, qwtGetDataBlock);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("dsGetDataBlock", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^dsGetDataBlock$", result); any.get_global_func_addr_dynsym("^dsGetDataBlock$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, qwtGetDataBlock); stub.set(f.second, qwtGetDataBlock);
} }
......
...@@ -621,13 +621,13 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu ...@@ -621,13 +621,13 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
if (subPos > 0) { if (subPos > 0) {
startPosBytes = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? subPos - 1 : (subPos - 1) * TSDB_NCHAR_SIZE; startPosBytes = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? subPos - 1 : (subPos - 1) * TSDB_NCHAR_SIZE;
startPosBytes = MIN(startPosBytes, len); startPosBytes = TMIN(startPosBytes, len);
} else { } else {
startPosBytes = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? len + subPos : len + subPos * TSDB_NCHAR_SIZE; startPosBytes = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? len + subPos : len + subPos * TSDB_NCHAR_SIZE;
startPosBytes = MAX(startPosBytes, 0); startPosBytes = TMAX(startPosBytes, 0);
} }
int32_t resLen = MIN(subLen, len - startPosBytes); int32_t resLen = TMIN(subLen, len - startPosBytes);
if (resLen > 0) { if (resLen > 0) {
memcpy(varDataVal(output), varDataVal(input) + startPosBytes, resLen); memcpy(varDataVal(output), varDataVal(input) + startPosBytes, resLen);
} }
...@@ -716,7 +716,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -716,7 +716,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE), *(int8_t *)input ? "true" : "false"); int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE), *(int8_t *)input ? "true" : "false");
varDataSetLen(output, len); varDataSetLen(output, len);
} else if (inputType == TSDB_DATA_TYPE_BINARY) { } else if (inputType == TSDB_DATA_TYPE_BINARY) {
int32_t len = MIN(varDataLen(input), outputLen - VARSTR_HEADER_SIZE); int32_t len = TMIN(varDataLen(input), outputLen - VARSTR_HEADER_SIZE);
len = sprintf(varDataVal(output), "%.*s", len, varDataVal(input)); len = sprintf(varDataVal(output), "%.*s", len, varDataVal(input));
varDataSetLen(output, len); varDataSetLen(output, len);
} else if (inputType == TSDB_DATA_TYPE_NCHAR) { } else if (inputType == TSDB_DATA_TYPE_NCHAR) {
...@@ -750,7 +750,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -750,7 +750,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
} }
varDataSetLen(output, len); varDataSetLen(output, len);
} else if (inputType == TSDB_DATA_TYPE_NCHAR) { } else if (inputType == TSDB_DATA_TYPE_NCHAR) {
int32_t len = MIN(outputLen, varDataLen(input) + VARSTR_HEADER_SIZE); int32_t len = TMIN(outputLen, varDataLen(input) + VARSTR_HEADER_SIZE);
memcpy(output, input, len); memcpy(output, input, len);
varDataSetLen(output, len - VARSTR_HEADER_SIZE); varDataSetLen(output, len - VARSTR_HEADER_SIZE);
} else { } else {
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
#pragma GCC diagnostic ignored "-Wpointer-arith" #pragma GCC diagnostic ignored "-Wpointer-arith"
#include <addr_any.h> #include <addr_any.h>
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "os.h" #include "os.h"
#include "tglobal.h" #include "tglobal.h"
...@@ -364,7 +367,7 @@ TEST(columnTest, smallint_column_greater_double_value) { ...@@ -364,7 +367,7 @@ TEST(columnTest, smallint_column_greater_double_value) {
keep = filterRangeExecute(filter, &stat, 1, rowNum); keep = filterRangeExecute(filter, &stat, 1, rowNum);
ASSERT_EQ(keep, true); ASSERT_EQ(keep, true);
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -419,7 +422,7 @@ TEST(columnTest, int_column_greater_smallint_value) { ...@@ -419,7 +422,7 @@ TEST(columnTest, int_column_greater_smallint_value) {
keep = filterRangeExecute(filter, &stat, 1, rowNum); keep = filterRangeExecute(filter, &stat, 1, rowNum);
ASSERT_EQ(keep, false); ASSERT_EQ(keep, false);
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -463,7 +466,7 @@ TEST(columnTest, int_column_in_double_list) { ...@@ -463,7 +466,7 @@ TEST(columnTest, int_column_in_double_list) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -527,7 +530,7 @@ TEST(columnTest, binary_column_in_binary_list) { ...@@ -527,7 +530,7 @@ TEST(columnTest, binary_column_in_binary_list) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -575,7 +578,7 @@ TEST(columnTest, binary_column_like_binary) { ...@@ -575,7 +578,7 @@ TEST(columnTest, binary_column_like_binary) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -622,7 +625,7 @@ TEST(columnTest, binary_column_is_null) { ...@@ -622,7 +625,7 @@ TEST(columnTest, binary_column_is_null) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -669,7 +672,7 @@ TEST(columnTest, binary_column_is_not_null) { ...@@ -669,7 +672,7 @@ TEST(columnTest, binary_column_is_not_null) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -706,7 +709,7 @@ TEST(opTest, smallint_column_greater_int_column) { ...@@ -706,7 +709,7 @@ TEST(opTest, smallint_column_greater_int_column) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -744,7 +747,7 @@ TEST(opTest, smallint_value_add_int_column) { ...@@ -744,7 +747,7 @@ TEST(opTest, smallint_value_add_int_column) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -787,7 +790,7 @@ TEST(opTest, bigint_column_multi_binary_column) { ...@@ -787,7 +790,7 @@ TEST(opTest, bigint_column_multi_binary_column) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -830,7 +833,7 @@ TEST(opTest, smallint_column_and_binary_column) { ...@@ -830,7 +833,7 @@ TEST(opTest, smallint_column_and_binary_column) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -868,7 +871,7 @@ TEST(opTest, smallint_column_or_float_column) { ...@@ -868,7 +871,7 @@ TEST(opTest, smallint_column_or_float_column) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -906,7 +909,7 @@ TEST(opTest, smallint_column_or_double_value) { ...@@ -906,7 +909,7 @@ TEST(opTest, smallint_column_or_double_value) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -950,7 +953,7 @@ TEST(opTest, binary_column_is_true) { ...@@ -950,7 +953,7 @@ TEST(opTest, binary_column_is_true) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1021,7 +1024,7 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { ...@@ -1021,7 +1024,7 @@ TEST(filterModelogicTest, diff_columns_and_or_and) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1090,7 +1093,7 @@ TEST(filterModelogicTest, same_column_and_or_and) { ...@@ -1090,7 +1093,7 @@ TEST(filterModelogicTest, same_column_and_or_and) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1159,7 +1162,7 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { ...@@ -1159,7 +1162,7 @@ TEST(filterModelogicTest, diff_columns_or_and_or) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1228,7 +1231,7 @@ TEST(filterModelogicTest, same_column_or_and_or) { ...@@ -1228,7 +1231,7 @@ TEST(filterModelogicTest, same_column_or_and_or) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1299,7 +1302,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { ...@@ -1299,7 +1302,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = {.numOfCols= src->info.numOfCols, .pDataBlock = src->pDataBlock}; SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock };
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
#pragma GCC diagnostic ignored "-Wpointer-arith" #pragma GCC diagnostic ignored "-Wpointer-arith"
#include <addr_any.h> #include <addr_any.h>
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "os.h" #include "os.h"
#include "tglobal.h" #include "tglobal.h"
......
...@@ -52,14 +52,26 @@ typedef struct SSchHbTrans { ...@@ -52,14 +52,26 @@ typedef struct SSchHbTrans {
typedef struct SSchApiStat { typedef struct SSchApiStat {
#ifdef WINDOWS
size_t avoidCompilationErrors;
#endif
} SSchApiStat; } SSchApiStat;
typedef struct SSchRuntimeStat { typedef struct SSchRuntimeStat {
#ifdef WINDOWS
size_t avoidCompilationErrors;
#endif
} SSchRuntimeStat; } SSchRuntimeStat;
typedef struct SSchJobStat { typedef struct SSchJobStat {
#ifdef WINDOWS
size_t avoidCompilationErrors;
#endif
} SSchJobStat; } SSchJobStat;
typedef struct SSchedulerStat { typedef struct SSchedulerStat {
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#pragma GCC diagnostic ignored "-Wformat" #pragma GCC diagnostic ignored "-Wformat"
#include <addr_any.h> #include <addr_any.h>
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "os.h" #include "os.h"
#include "tglobal.h" #include "tglobal.h"
...@@ -275,9 +277,16 @@ void schtSetPlanToString() { ...@@ -275,9 +277,16 @@ void schtSetPlanToString() {
static Stub stub; static Stub stub;
stub.set(qSubPlanToString, schtPlanToString); stub.set(qSubPlanToString, schtPlanToString);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("qSubPlanToString", result);
#endif
#ifdef LINUX
AddrAny any("libplanner.so"); AddrAny any("libplanner.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^qSubPlanToString$", result); any.get_global_func_addr_dynsym("^qSubPlanToString$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, schtPlanToString); stub.set(f.second, schtPlanToString);
} }
...@@ -288,9 +297,16 @@ void schtSetExecNode() { ...@@ -288,9 +297,16 @@ void schtSetExecNode() {
static Stub stub; static Stub stub;
stub.set(qSetSubplanExecutionNode, schtExecNode); stub.set(qSetSubplanExecutionNode, schtExecNode);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("qSetSubplanExecutionNode", result);
#endif
#ifdef LINUX
AddrAny any("libplanner.so"); AddrAny any("libplanner.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^qSetSubplanExecutionNode$", result); any.get_global_func_addr_dynsym("^qSetSubplanExecutionNode$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, schtExecNode); stub.set(f.second, schtExecNode);
} }
...@@ -301,9 +317,16 @@ void schtSetRpcSendRequest() { ...@@ -301,9 +317,16 @@ void schtSetRpcSendRequest() {
static Stub stub; static Stub stub;
stub.set(rpcSendRequest, schtRpcSendRequest); stub.set(rpcSendRequest, schtRpcSendRequest);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("rpcSendRequest", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^rpcSendRequest$", result); any.get_global_func_addr_dynsym("^rpcSendRequest$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, schtRpcSendRequest); stub.set(f.second, schtRpcSendRequest);
} }
...@@ -324,9 +347,16 @@ void schtSetAsyncSendMsgToServer() { ...@@ -324,9 +347,16 @@ void schtSetAsyncSendMsgToServer() {
static Stub stub; static Stub stub;
stub.set(asyncSendMsgToServer, schtAsyncSendMsgToServer); stub.set(asyncSendMsgToServer, schtAsyncSendMsgToServer);
{ {
#ifdef WINDOWS
AddrAny any;
std::map<std::string,void*> result;
any.get_func_addr("asyncSendMsgToServer", result);
#endif
#ifdef LINUX
AddrAny any("libtransport.so"); AddrAny any("libtransport.so");
std::map<std::string,void*> result; std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^asyncSendMsgToServer$", result); any.get_global_func_addr_dynsym("^asyncSendMsgToServer$", result);
#endif
for (const auto& f : result) { for (const auto& f : result) {
stub.set(f.second, schtAsyncSendMsgToServer); stub.set(f.second, schtAsyncSendMsgToServer);
} }
...@@ -382,6 +412,7 @@ void *schtCreateFetchRspThread(void *param) { ...@@ -382,6 +412,7 @@ void *schtCreateFetchRspThread(void *param) {
schReleaseJob(job); schReleaseJob(job);
assert(code == 0); assert(code == 0);
return NULL;
} }
...@@ -413,6 +444,7 @@ void *schtFetchRspThread(void *aa) { ...@@ -413,6 +444,7 @@ void *schtFetchRspThread(void *aa) {
assert(code == 0 || code); assert(code == 0 || code);
} }
return NULL;
} }
void schtFreeQueryJob(int32_t freeThread) { void schtFreeQueryJob(int32_t freeThread) {
...@@ -595,6 +627,7 @@ void* schtRunJobThread(void *aa) { ...@@ -595,6 +627,7 @@ void* schtRunJobThread(void *aa) {
schedulerDestroy(); schedulerDestroy();
return NULL;
} }
void* schtFreeJobThread(void *aa) { void* schtFreeJobThread(void *aa) {
...@@ -602,6 +635,7 @@ void* schtFreeJobThread(void *aa) { ...@@ -602,6 +635,7 @@ void* schtFreeJobThread(void *aa) {
taosUsleep(taosRand() % 100); taosUsleep(taosRand() % 100);
schtFreeQueryJob(1); schtFreeQueryJob(1);
} }
return NULL;
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
*/ */
#include "syncEnv.h" #include "syncEnv.h"
#include <assert.h> // #include <assert.h>
SSyncEnv *gSyncEnv = NULL; SSyncEnv *gSyncEnv = NULL;
......
# tdb # tdb
add_library(tdb "") add_library(tdb STATIC "")
target_sources(tdb target_sources(tdb
PRIVATE PRIVATE
"src/db/tdbPCache.c" "src/db/tdbPCache.c"
......
...@@ -42,14 +42,17 @@ struct SBTree { ...@@ -42,14 +42,17 @@ struct SBTree {
ASSERT(TDB_FLAG_IS(flags, TDB_BTREE_ROOT) || TDB_FLAG_IS(flags, TDB_BTREE_LEAF) || \ ASSERT(TDB_FLAG_IS(flags, TDB_BTREE_ROOT) || TDB_FLAG_IS(flags, TDB_BTREE_LEAF) || \
TDB_FLAG_IS(flags, TDB_BTREE_ROOT | TDB_BTREE_LEAF) || TDB_FLAG_IS(flags, 0)) TDB_FLAG_IS(flags, TDB_BTREE_ROOT | TDB_BTREE_LEAF) || TDB_FLAG_IS(flags, 0))
typedef struct __attribute__((__packed__)) {
#pragma pack(push,1)
typedef struct {
TDB_BTREE_PAGE_COMMON_HDR TDB_BTREE_PAGE_COMMON_HDR
} SLeafHdr; } SLeafHdr;
typedef struct __attribute__((__packed__)) { typedef struct {
TDB_BTREE_PAGE_COMMON_HDR; TDB_BTREE_PAGE_COMMON_HDR
SPgno pgno; // right-most child SPgno pgno; // right-most child
} SIntHdr; } SIntHdr;
#pragma pack(pop)
typedef struct { typedef struct {
u8 flags; u8 flags;
......
...@@ -28,11 +28,10 @@ struct SPCache { ...@@ -28,11 +28,10 @@ struct SPCache {
SPage lru; SPage lru;
}; };
#define PCACHE_PAGE_HASH(pPgid) \ static inline int tdbPCachePageHash(const SPgid *pPgid) {
({ \ u32 *t = (u32 *)((pPgid)->fileid);
u32 *t = (u32 *)((pPgid)->fileid); \ return t[0] + t[1] + t[2] + t[3] + t[4] + t[5] + (pPgid)->pgno;
t[0] + t[1] + t[2] + t[3] + t[4] + t[5] + (pPgid)->pgno; \ }
})
#define PAGE_IS_PINNED(pPage) ((pPage)->pLruNext == NULL) #define PAGE_IS_PINNED(pPage) ((pPage)->pLruNext == NULL)
static int tdbPCacheOpenImpl(SPCache *pCache); static int tdbPCacheOpenImpl(SPCache *pCache);
...@@ -130,7 +129,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) ...@@ -130,7 +129,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn)
SPage *pPage; SPage *pPage;
// 1. Search the hash table // 1. Search the hash table
pPage = pCache->pgHash[PCACHE_PAGE_HASH(pPgid) % pCache->nHash]; pPage = pCache->pgHash[tdbPCachePageHash(pPgid) % pCache->nHash];
while (pPage) { while (pPage) {
if (TDB_IS_SAME_PAGE(&(pPage->pgid), pPgid)) break; if (TDB_IS_SAME_PAGE(&(pPage->pgid), pPgid)) break;
pPage = pPage->pHashNext; pPage = pPage->pHashNext;
...@@ -218,7 +217,7 @@ static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage) { ...@@ -218,7 +217,7 @@ static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage) {
SPage **ppPage; SPage **ppPage;
int h; int h;
h = PCACHE_PAGE_HASH(&(pPage->pgid)); h = tdbPCachePageHash(&(pPage->pgid));
for (ppPage = &(pCache->pgHash[h % pCache->nHash]); *ppPage != pPage; ppPage = &((*ppPage)->pHashNext)) for (ppPage = &(pCache->pgHash[h % pCache->nHash]); *ppPage != pPage; ppPage = &((*ppPage)->pHashNext))
; ;
ASSERT(*ppPage == pPage); ASSERT(*ppPage == pPage);
...@@ -230,7 +229,7 @@ static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage) { ...@@ -230,7 +229,7 @@ static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage) {
static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage) { static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage) {
int h; int h;
h = PCACHE_PAGE_HASH(&(pPage->pgid)) % pCache->nHash; h = tdbPCachePageHash(&(pPage->pgid)) % pCache->nHash;
pPage->pHashNext = pCache->pgHash[h]; pPage->pHashNext = pCache->pgHash[h];
pCache->pgHash[h] = pPage; pCache->pgHash[h] = pPage;
......
...@@ -435,17 +435,20 @@ static int tdbPageDefragment(SPage *pPage) { ...@@ -435,17 +435,20 @@ static int tdbPageDefragment(SPage *pPage) {
} }
/* ---------------------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------------------- */
typedef struct __attribute__((__packed__)) {
#pragma pack(push,1)
typedef struct {
u16 cellNum; u16 cellNum;
u16 cellBody; u16 cellBody;
u16 cellFree; u16 cellFree;
u16 nFree; u16 nFree;
} SPageHdr; } SPageHdr;
typedef struct __attribute__((__packed__)) { typedef struct {
u16 szCell; u16 szCell;
u16 nxOffset; u16 nxOffset;
} SFreeCell; } SFreeCell;
#pragma pack(pop)
// cellNum // cellNum
static inline int getPageCellNum(SPage *pPage) { return ((SPageHdr *)(pPage->pPageHdr))[0].cellNum; } static inline int getPageCellNum(SPage *pPage) { return ((SPageHdr *)(pPage->pPageHdr))[0].cellNum; }
...@@ -517,17 +520,19 @@ SPageMethods pageMethods = { ...@@ -517,17 +520,19 @@ SPageMethods pageMethods = {
setPageFreeCellInfo // setFreeCellInfo setPageFreeCellInfo // setFreeCellInfo
}; };
typedef struct __attribute__((__packed__)) { #pragma pack(push,1)
typedef struct {
u8 cellNum[3]; u8 cellNum[3];
u8 cellBody[3]; u8 cellBody[3];
u8 cellFree[3]; u8 cellFree[3];
u8 nFree[3]; u8 nFree[3];
} SPageHdrL; } SPageHdrL;
typedef struct __attribute__((__packed__)) { typedef struct {
u8 szCell[3]; u8 szCell[3];
u8 nxOffset[3]; u8 nxOffset[3];
} SFreeCellL; } SFreeCellL;
#pragma pack(pop)
// cellNum // cellNum
static inline int getLPageCellNum(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum); } static inline int getLPageCellNum(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum); }
......
...@@ -15,13 +15,15 @@ ...@@ -15,13 +15,15 @@
#include "tdbInt.h" #include "tdbInt.h"
typedef struct __attribute__((__packed__)) { #pragma pack(push,1)
typedef struct {
u8 hdrString[16]; u8 hdrString[16];
u16 pageSize; u16 pageSize;
SPgno freePage; SPgno freePage;
u32 nFreePages; u32 nFreePages;
u8 reserved[102]; u8 reserved[102];
} SFileHdr; } SFileHdr;
#pragma pack(pop)
TDB_STATIC_ASSERT(sizeof(SFileHdr) == 128, "Size of file header is not correct"); TDB_STATIC_ASSERT(sizeof(SFileHdr) == 128, "Size of file header is not correct");
......
...@@ -47,10 +47,13 @@ typedef struct { ...@@ -47,10 +47,13 @@ typedef struct {
void (*setFreeCellInfo)(SCell *pCell, int szCell, int nxOffset); void (*setFreeCellInfo)(SCell *pCell, int szCell, int nxOffset);
} SPageMethods; } SPageMethods;
#pragma pack(push,1)
// Page footer // Page footer
typedef struct __attribute__((__packed__)) { typedef struct {
u8 cksm[4]; u8 cksm[4];
} SPageFtr; } SPageFtr;
#pragma pack(pop)
struct SPage { struct SPage {
tdb_spinlock_t lock; tdb_spinlock_t lock;
...@@ -80,22 +83,23 @@ struct SPage { ...@@ -80,22 +83,23 @@ struct SPage {
#define P_LOCK_BUSY 1 #define P_LOCK_BUSY 1
#define P_LOCK_FAIL -1 #define P_LOCK_FAIL -1
static inline int tdbTryLockPage(tdb_spinlock_t *pLock) {
int ret;
if (tdbSpinlockTrylock(pLock) == 0) {
ret = P_LOCK_SUCC;
} else if (errno == EBUSY) {
ret = P_LOCK_BUSY;
} else {
ret = P_LOCK_FAIL;
}
return ret;
}
#define TDB_INIT_PAGE_LOCK(pPage) tdbSpinlockInit(&((pPage)->lock), 0) #define TDB_INIT_PAGE_LOCK(pPage) tdbSpinlockInit(&((pPage)->lock), 0)
#define TDB_DESTROY_PAGE_LOCK(pPage) tdbSpinlockDestroy(&((pPage)->lock)) #define TDB_DESTROY_PAGE_LOCK(pPage) tdbSpinlockDestroy(&((pPage)->lock))
#define TDB_LOCK_PAGE(pPage) tdbSpinlockLock(&((pPage)->lock)) #define TDB_LOCK_PAGE(pPage) tdbSpinlockLock(&((pPage)->lock))
#define TDB_UNLOCK_PAGE(pPage) tdbSpinlockUnlock(&((pPage)->lock)) #define TDB_UNLOCK_PAGE(pPage) tdbSpinlockUnlock(&((pPage)->lock))
#define TDB_TRY_LOCK_PAGE(pPage) \ #define TDB_TRY_LOCK_PAGE(pPage) tdbTryLockPage(&((pPage)->lock))
({ \
int ret; \
if (tdbSpinlockTrylock(&((pPage)->lock)) == 0) { \
ret = P_LOCK_SUCC; \
} else if (errno == EBUSY) { \
ret = P_LOCK_BUSY; \
} else { \
ret = P_LOCK_FAIL; \
} \
ret; \
})
// APIs // APIs
#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage)) #define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage))
......
...@@ -31,20 +31,20 @@ extern "C" { ...@@ -31,20 +31,20 @@ extern "C" {
int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique); int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique);
int tdbGetFileSize(tdb_fd_t fd, int szPage, SPgno *size); int tdbGetFileSize(tdb_fd_t fd, int szPage, SPgno *size);
#define TDB_REALLOC(PTR, SIZE) \ static inline void *tdbRealloc(void *ptr, size_t size) {
({ \ void *nPtr;
void *nPtr; \ if ((ptr) == NULL || ((int *)(ptr))[-1] < (size)) {
if ((PTR) == NULL || ((int *)(PTR))[-1] < (SIZE)) { \ nPtr = tdbOsRealloc((ptr) ? (char *)(ptr) - sizeof(int) : NULL, (size) + sizeof(int));
nPtr = tdbOsRealloc((PTR) ? (char *)(PTR) - sizeof(int) : NULL, (SIZE) + sizeof(int)); \ if (nPtr) {
if (nPtr) { \ ((int *)nPtr)[0] = (size);
((int *)nPtr)[0] = (SIZE); \ nPtr = (char *)nPtr + sizeof(int);
nPtr = (char *)nPtr + sizeof(int); \ }
} \ } else {
} else { \ nPtr = (ptr);
nPtr = (PTR); \ }
} \ return nPtr;
nPtr; \ }
}) #define TDB_REALLOC(PTR, SIZE) tdbRealloc(PTR, SIZE)
#define TDB_FREE(PTR) \ #define TDB_FREE(PTR) \
do { \ do { \
......
...@@ -366,7 +366,7 @@ const STfsFile *tfsReaddir(STfsDir *pTfsDir) { ...@@ -366,7 +366,7 @@ const STfsFile *tfsReaddir(STfsDir *pTfsDir) {
void tfsClosedir(STfsDir *pTfsDir) { void tfsClosedir(STfsDir *pTfsDir) {
if (pTfsDir) { if (pTfsDir) {
if (pTfsDir->pDir != NULL) { if (pTfsDir->pDir != NULL) {
taosCloseDir(pTfsDir->pDir); taosCloseDir(&pTfsDir->pDir);
pTfsDir->pDir = NULL; pTfsDir->pDir = NULL;
} }
taosMemoryFree(pTfsDir); taosMemoryFree(pTfsDir);
...@@ -455,7 +455,7 @@ static int32_t tfsFormatDir(char *idir, char *odir) { ...@@ -455,7 +455,7 @@ static int32_t tfsFormatDir(char *idir, char *odir) {
} }
char tmp[PATH_MAX] = {0}; char tmp[PATH_MAX] = {0};
if (realpath(wep.we_wordv[0], tmp) == NULL) { if (taosRealPath(wep.we_wordv[0], tmp, PATH_MAX) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
wordfree(&wep); wordfree(&wep);
return -1; return -1;
...@@ -499,7 +499,7 @@ static int32_t tfsOpendirImpl(STfs *pTfs, STfsDir *pTfsDir) { ...@@ -499,7 +499,7 @@ static int32_t tfsOpendirImpl(STfs *pTfs, STfsDir *pTfsDir) {
char adir[TMPNAME_LEN * 2] = "\0"; char adir[TMPNAME_LEN * 2] = "\0";
if (pTfsDir->pDir != NULL) { if (pTfsDir->pDir != NULL) {
taosCloseDir(pTfsDir->pDir); taosCloseDir(&pTfsDir->pDir);
pTfsDir->pDir = NULL; pTfsDir->pDir = NULL;
} }
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <sys/time.h>
#include <tdatablock.h> #include <tdatablock.h>
#include "os.h" #include "os.h"
#include "rpcLog.h" #include "rpcLog.h"
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <sys/time.h>
#include <tdatablock.h> #include <tdatablock.h>
#include "os.h" #include "os.h"
#include "rpcLog.h" #include "rpcLog.h"
......
...@@ -156,14 +156,14 @@ TEST_F(TransCtxEnv, mergeTest) { ...@@ -156,14 +156,14 @@ TEST_F(TransCtxEnv, mergeTest) {
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx)); STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
transCtxInit(src); transCtxInit(src);
{ {
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = (void (*)(const void*))taosMemoryFree}; STransCtxVal val1 = { NULL, NULL, (void (*)(const void*))taosMemoryFree};
val1.val = taosMemoryMalloc(12); val1.val = taosMemoryMalloc(12);
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
key++; key++;
} }
{ {
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = (void (*)(const void*))taosMemoryFree}; STransCtxVal val1 = { NULL, NULL, (void (*)(const void*))taosMemoryFree};
val1.val = taosMemoryMalloc(12); val1.val = taosMemoryMalloc(12);
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
key++; key++;
...@@ -176,14 +176,14 @@ TEST_F(TransCtxEnv, mergeTest) { ...@@ -176,14 +176,14 @@ TEST_F(TransCtxEnv, mergeTest) {
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx)); STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
transCtxInit(src); transCtxInit(src);
{ {
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = (void (*)(const void*))taosMemoryFree}; STransCtxVal val1 = { NULL, NULL, (void (*)(const void*))taosMemoryFree};
val1.val = taosMemoryMalloc(12); val1.val = taosMemoryMalloc(12);
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
key++; key++;
} }
{ {
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = (void (*)(const void*))taosMemoryFree}; STransCtxVal val1 = { NULL, NULL, (void (*)(const void*))taosMemoryFree};
val1.val = taosMemoryMalloc(12); val1.val = taosMemoryMalloc(12);
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
key++; key++;
...@@ -198,7 +198,7 @@ TEST_F(TransCtxEnv, mergeTest) { ...@@ -198,7 +198,7 @@ TEST_F(TransCtxEnv, mergeTest) {
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx)); STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
transCtxInit(src); transCtxInit(src);
{ {
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = (void (*)(const void*))taosMemoryFree}; STransCtxVal val1 = { NULL, NULL, (void (*)(const void*))taosMemoryFree};
val1.val = taosMemoryCalloc(1, 11); val1.val = taosMemoryCalloc(1, 11);
memcpy(val1.val, val.c_str(), val.size()); memcpy(val1.val, val.c_str(), val.size());
...@@ -206,7 +206,7 @@ TEST_F(TransCtxEnv, mergeTest) { ...@@ -206,7 +206,7 @@ TEST_F(TransCtxEnv, mergeTest) {
key++; key++;
} }
{ {
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = (void (*)(const void*))taosMemoryFree}; STransCtxVal val1 = { NULL, NULL, (void (*)(const void*))taosMemoryFree};
val1.val = taosMemoryCalloc(1, 11); val1.val = taosMemoryCalloc(1, 11);
memcpy(val1.val, val.c_str(), val.size()); memcpy(val1.val, val.c_str(), val.size());
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
......
...@@ -145,7 +145,7 @@ int walCheckAndRepairMeta(SWal* pWal) { ...@@ -145,7 +145,7 @@ int walCheckAndRepairMeta(SWal* pWal) {
} }
} }
taosCloseDir(pDir); taosCloseDir(&pDir);
regfree(&logRegPattern); regfree(&logRegPattern);
regfree(&idxRegPattern); regfree(&idxRegPattern);
...@@ -351,7 +351,7 @@ static int walFindCurMetaVer(SWal* pWal) { ...@@ -351,7 +351,7 @@ static int walFindCurMetaVer(SWal* pWal) {
break; break;
} }
} }
taosCloseDir(pDir); taosCloseDir(&pDir);
regfree(&walMetaRegexPattern); regfree(&walMetaRegexPattern);
return metaVer; return metaVer;
} }
......
...@@ -6,7 +6,8 @@ target_include_directories( ...@@ -6,7 +6,8 @@ target_include_directories(
PUBLIC "${TD_SOURCE_DIR}/include" PUBLIC "${TD_SOURCE_DIR}/include"
PUBLIC "${TD_SOURCE_DIR}/include/util" PUBLIC "${TD_SOURCE_DIR}/include/util"
PUBLIC "${TD_SOURCE_DIR}/contrib/pthread" PUBLIC "${TD_SOURCE_DIR}/contrib/pthread"
PUBLIC "${TD_SOURCE_DIR}/contrib/gnuregex" PUBLIC "${TD_SOURCE_DIR}/contrib/iconv"
PUBLIC "${TD_SOURCE_DIR}/contrib/msvcregex"
) )
# iconv # iconv
find_path(IconvApiIncludes iconv.h PATHS) find_path(IconvApiIncludes iconv.h PATHS)
...@@ -17,5 +18,14 @@ if(USE_TD_MEMORY) ...@@ -17,5 +18,14 @@ if(USE_TD_MEMORY)
add_definitions(-DUSE_TD_MEMORY) add_definitions(-DUSE_TD_MEMORY)
endif () endif ()
target_link_libraries( target_link_libraries(
os pthread dl rt m os pthread
) )
if(NOT TD_WINDOWS)
target_link_libraries(
os dl m rt
)
else()
target_link_libraries(
os ws2_32 iconv msvcregex wcwidth winmm
)
endif(NOT TD_WINDOWS)
此差异已折叠。
...@@ -17,19 +17,40 @@ ...@@ -17,19 +17,40 @@
#define ALLOW_FORBID_FUNC #define ALLOW_FORBID_FUNC
#include "os.h" #include "os.h"
#include "osString.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
/*
* windows implementation #include <windows.h>
*/
typedef struct TdDirEntry {
WIN32_FIND_DATA findFileData;
} TdDirEntry;
typedef struct TdDir {
TdDirEntry dirEntry;
HANDLE hFind;
} TdDir;
int wordexp(char *words, wordexp_t *pwordexp, int flags) {
pwordexp->we_offs = 0;
pwordexp->we_wordc = 1;
pwordexp->we_wordv[0] = pwordexp->wordPos;
memset(pwordexp->wordPos, 0, 1025);
if (_fullpath(pwordexp->wordPos, words, 1024) == NULL) {
pwordexp->we_wordv[0] = words;
printf("failed to parse relative path:%s to abs path", words);
return -1;
}
printf("parse relative path:%s to abs path:%s", words, pwordexp->wordPos);
return 0;
}
// todo void wordfree(wordexp_t *pwordexp) {}
#else #else
/*
* linux implementation
*/
#include <dirent.h> #include <dirent.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -39,19 +60,21 @@ ...@@ -39,19 +60,21 @@
typedef struct dirent dirent; typedef struct dirent dirent;
typedef struct DIR TdDir; typedef struct DIR TdDir;
typedef struct dirent TdDirent; typedef struct dirent TdDirEntry;
#endif
void taosRemoveDir(const char *dirname) { void taosRemoveDir(const char *dirname) {
DIR *dir = opendir(dirname); TdDirPtr pDir = taosOpenDir(dirname);
if (dir == NULL) return; if (pDir == NULL) return;
struct dirent *de = NULL; TdDirEntryPtr de = NULL;
while ((de = readdir(dir)) != NULL) { while ((de = taosReadDir(pDir)) != NULL) {
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue; if (strcmp(taosGetDirEntryName(de), ".") == 0 || strcmp(taosGetDirEntryName(de), "..") == 0) continue;
char filename[1024]; char filename[1024];
snprintf(filename, sizeof(filename), "%s/%s", dirname, de->d_name); snprintf(filename, sizeof(filename), "%s/%s", dirname, taosGetDirEntryName(de));
if (de->d_type & DT_DIR) { if (taosDirEntryIsDir(de)) {
taosRemoveDir(filename); taosRemoveDir(filename);
} else { } else {
(void)taosRemoveFile(filename); (void)taosRemoveFile(filename);
...@@ -59,13 +82,14 @@ void taosRemoveDir(const char *dirname) { ...@@ -59,13 +82,14 @@ void taosRemoveDir(const char *dirname) {
} }
} }
closedir(dir); taosCloseDir(&pDir);
rmdir(dirname); rmdir(dirname);
//printf("dir:%s is removed\n", dirname); //printf("dir:%s is removed\n", dirname);
return;
} }
bool taosDirExist(char *dirname) { return taosCheckExistFile(dirname); } bool taosDirExist(const char *dirname) { return taosCheckExistFile(dirname); }
int32_t taosMkDir(const char *dirname) { int32_t taosMkDir(const char *dirname) {
int32_t code = mkdir(dirname, 0755); int32_t code = mkdir(dirname, 0755);
...@@ -118,18 +142,18 @@ int32_t taosMulMkDir(const char *dirname) { ...@@ -118,18 +142,18 @@ int32_t taosMulMkDir(const char *dirname) {
} }
void taosRemoveOldFiles(const char *dirname, int32_t keepDays) { void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
DIR *dir = opendir(dirname); TdDirPtr pDir = taosOpenDir(dirname);
if (dir == NULL) return; if (pDir == NULL) return;
int64_t sec = taosGetTimestampSec(); int64_t sec = taosGetTimestampSec();
struct dirent *de = NULL; TdDirEntryPtr de = NULL;
while ((de = readdir(dir)) != NULL) { while ((de = taosReadDir(pDir)) != NULL) {
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue; if (strcmp(taosGetDirEntryName(de), ".") == 0 || strcmp(taosGetDirEntryName(de), "..") == 0) continue;
char filename[1024]; char filename[1024];
snprintf(filename, sizeof(filename), "%s/%s", dirname, de->d_name); snprintf(filename, sizeof(filename), "%s/%s", dirname, taosGetDirEntryName(de));
if (de->d_type & DT_DIR) { if (taosDirEntryIsDir(de)) {
continue; continue;
} else { } else {
int32_t len = (int32_t)strlen(filename); int32_t len = (int32_t)strlen(filename);
...@@ -156,7 +180,7 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) { ...@@ -156,7 +180,7 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
} }
} }
closedir(dir); taosCloseDir(&pDir);
rmdir(dirname); rmdir(dirname);
} }
...@@ -177,65 +201,131 @@ int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { ...@@ -177,65 +201,131 @@ int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
return 0; return 0;
} }
int32_t taosRealPath(char *dirname, int32_t maxlen) { int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) {
char tmp[PATH_MAX] = {0}; char tmp[PATH_MAX] = {0};
#ifdef WINDOWS
if (_fullpath(dirname, tmp, maxlen) != NULL) {
#else
if (realpath(dirname, tmp) != NULL) { if (realpath(dirname, tmp) != NULL) {
strncpy(dirname, tmp, maxlen); #endif
if (realPath == NULL) {
strncpy(dirname, tmp, maxlen);
} else {
strncpy(realPath, tmp, maxlen);
}
return 0;
} }
return 0; return -1;
} }
bool taosIsDir(const char *dirname) { bool taosIsDir(const char *dirname) {
DIR *dir = opendir(dirname); TdDirPtr pDir = taosOpenDir(dirname);
if (dir != NULL) { if (pDir != NULL) {
closedir(dir); taosCloseDir(&pDir);
return true; return true;
} }
return false; return false;
} }
char* taosDirName(char *name) { char* taosDirName(char *name) {
#ifdef WINDOWS
char Drive1[MAX_PATH], Dir1[MAX_PATH];
_splitpath(name, Drive1, Dir1, NULL, NULL);
size_t dirNameLen = strlen(Drive1) + strlen(Dir1);
if (dirNameLen > 0) {
name[dirNameLen] = 0;
}
return name;
#else
return dirname(name); return dirname(name);
#endif
} }
char* taosDirEntryBaseName(char *name) { char* taosDirEntryBaseName(char *name) {
return basename(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);
#endif
} }
TdDirPtr taosOpenDir(const char *dirname) { TdDirPtr taosOpenDir(const char *dirname) {
if (dirname == NULL) { if (dirname == NULL) {
return NULL; return NULL;
} }
#ifdef WINDOWS
char szFind[MAX_PATH]; //这是要找的
HANDLE hFind;
TdDirPtr pDir = taosMemoryMalloc(sizeof(TdDir));
strcpy(szFind, dirname);
strcat(szFind, "\\*.*"); //利用通配符找这个目录下的所以文件,包括目录
pDir->hFind = FindFirstFile(szFind, &(pDir->dirEntry.findFileData));
if (INVALID_HANDLE_VALUE == pDir->hFind) {
taosMemoryFree(pDir);
return NULL;
}
return pDir;
#else
return (TdDirPtr)opendir(dirname); return (TdDirPtr)opendir(dirname);
#endif
} }
TdDirEntryPtr taosReadDir(TdDirPtr pDir) { TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
if (pDir == NULL) { if (pDir == NULL) {
return NULL; return NULL;
} }
#ifdef WINDOWS
if (!FindNextFile(pDir->hFind, &(pDir->dirEntry.findFileData))) {
return NULL;
}
return (TdDirEntryPtr)&(pDir->dirEntry.findFileData);
#else
return (TdDirEntryPtr)readdir((DIR*)pDir); return (TdDirEntryPtr)readdir((DIR*)pDir);
#endif
} }
bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) { bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) {
if (pDirEntry == NULL) { if (pDirEntry == NULL) {
return false; return false;
} }
#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) { if (pDirEntry == NULL) {
return NULL; return NULL;
} }
#ifdef WINDOWS
return pDirEntry->findFileData.cFileName;
#else
return ((dirent*)pDirEntry)->d_name; return ((dirent*)pDirEntry)->d_name;
#endif
} }
int32_t taosCloseDir(TdDirPtr pDir) { int32_t taosCloseDir(TdDirPtr *ppDir) {
if (pDir == NULL) { if (ppDir == NULL || *ppDir == NULL) {
return -1; return -1;
} }
return closedir((DIR*)pDir); #ifdef WINDOWS
} FindClose((*ppDir)->hFind);
taosMemoryFree(*ppDir);
*ppDir = NULL;
return 0;
#else
closedir((DIR*)*ppDir);
*ppDir = NULL;
return 0;
#endif #endif
}
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "osEnv.h" #include "osEnv.h"
extern void taosWinSocketInit();
char configDir[PATH_MAX] = {0}; char configDir[PATH_MAX] = {0};
char tsDataDir[PATH_MAX] = {0}; char tsDataDir[PATH_MAX] = {0};
char tsLogDir[PATH_MAX] = {0}; char tsLogDir[PATH_MAX] = {0};
...@@ -51,7 +49,7 @@ void osDefaultInit() { ...@@ -51,7 +49,7 @@ void osDefaultInit() {
tsNumOfCores = 2; tsNumOfCores = 2;
} }
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
taosWinSocketInit(); taosWinSocketInit();
const char *tmpDir = getenv("tmp"); const char *tmpDir = getenv("tmp");
......
...@@ -16,8 +16,11 @@ ...@@ -16,8 +16,11 @@
#include "os.h" #include "os.h"
#include "osSemaphore.h" #include "osSemaphore.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#include <io.h> #include <io.h>
#define F_OK 0
#define W_OK 2
#define R_OK 4
#if defined(_MSDOS) #if defined(_MSDOS)
#define open _open #define open _open
...@@ -33,6 +36,8 @@ extern int openU(const char *, int, ...); /* MsvcLibX UTF-8 version of open */ ...@@ -33,6 +36,8 @@ extern int openU(const char *, int, ...); /* MsvcLibX UTF-8 version of open */
#endif /* defined(_UTF8_SOURCE) */ #endif /* defined(_UTF8_SOURCE) */
#endif /* defined(_WIN32) */ #endif /* defined(_WIN32) */
#define _SEND_FILE_STEP_ 1000
#else #else
#include <fcntl.h> #include <fcntl.h>
#include <sys/file.h> #include <sys/file.h>
...@@ -66,7 +71,7 @@ typedef struct TdFile { ...@@ -66,7 +71,7 @@ typedef struct TdFile {
#define FILE_WITH_LOCK 1 #define FILE_WITH_LOCK 1
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath) { void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
const char *tdengineTmpFileNamePrefix = "tdengine-"; const char *tdengineTmpFileNamePrefix = "tdengine-";
char tmpPath[PATH_MAX]; char tmpPath[PATH_MAX];
...@@ -117,7 +122,7 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, cha ...@@ -117,7 +122,7 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, cha
} }
int64_t taosCopyFile(const char *from, const char *to) { int64_t taosCopyFile(const char *from, const char *to) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return 0; return 0;
#else #else
char buffer[4096]; char buffer[4096];
...@@ -160,7 +165,7 @@ _err: ...@@ -160,7 +165,7 @@ _err:
int32_t taosRemoveFile(const char *path) { return remove(path); } int32_t taosRemoveFile(const char *path) { return remove(path); }
int32_t taosRenameFile(const char *oldName, const char *newName) { int32_t taosRenameFile(const char *oldName, const char *newName) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
int32_t code = MoveFileEx(oldName, newName, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED); int32_t code = MoveFileEx(oldName, newName, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
if (code < 0) { if (code < 0) {
// printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno)); // printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno));
...@@ -178,7 +183,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) { ...@@ -178,7 +183,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
} }
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) { int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return 0; return 0;
#else #else
struct stat fileStat; struct stat fileStat;
...@@ -199,7 +204,7 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) { ...@@ -199,7 +204,7 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) {
#endif #endif
} }
int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno) { int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return 0; return 0;
#else #else
struct stat fileStat; struct stat fileStat;
...@@ -223,7 +228,7 @@ int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno) { ...@@ -223,7 +228,7 @@ int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno) {
void autoDelFileListAdd(const char *path) { return; } void autoDelFileListAdd(const char *path) { return; }
TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return NULL; return NULL;
#else #else
int fd = -1; int fd = -1;
...@@ -285,7 +290,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { ...@@ -285,7 +290,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
} }
int64_t taosCloseFile(TdFilePtr *ppFile) { int64_t taosCloseFile(TdFilePtr *ppFile) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return 0; return 0;
#else #else
if (ppFile == NULL || *ppFile == NULL) { if (ppFile == NULL || *ppFile == NULL) {
...@@ -365,8 +370,15 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) ...@@ -365,8 +370,15 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
#if FILE_WITH_LOCK #if FILE_WITH_LOCK
taosThreadRwlockRdlock(&(pFile->rwlock)); taosThreadRwlockRdlock(&(pFile->rwlock));
#endif #endif
assert(pFile->fd >= 0); // Please check if you have closed the file. assert(pFile->fd >= 0); // Please check if you have closed the file.
#ifdef WINDOWS
size_t pos = lseek(pFile->fd, 0, SEEK_CUR);
lseek(pFile->fd, (long)offset, SEEK_SET);
int64_t ret = read(pFile->fd, buf, count);
lseek(pFile->fd, pos, SEEK_SET);
#else
int64_t ret = pread(pFile->fd, buf, count, offset); int64_t ret = pread(pFile->fd, buf, count, offset);
#endif
#if FILE_WITH_LOCK #if FILE_WITH_LOCK
taosThreadRwlockUnlock(&(pFile->rwlock)); taosThreadRwlockUnlock(&(pFile->rwlock));
#endif #endif
...@@ -423,7 +435,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { ...@@ -423,7 +435,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
} }
int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return 0; return 0;
#else #else
if (pFile == NULL) { if (pFile == NULL) {
...@@ -450,7 +462,7 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { ...@@ -450,7 +462,7 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
} }
int32_t taosLockFile(TdFilePtr pFile) { int32_t taosLockFile(TdFilePtr pFile) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return 0; return 0;
#else #else
if (pFile == NULL) { if (pFile == NULL) {
...@@ -463,7 +475,7 @@ int32_t taosLockFile(TdFilePtr pFile) { ...@@ -463,7 +475,7 @@ int32_t taosLockFile(TdFilePtr pFile) {
} }
int32_t taosUnLockFile(TdFilePtr pFile) { int32_t taosUnLockFile(TdFilePtr pFile) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return 0; return 0;
#else #else
if (pFile == NULL) { if (pFile == NULL) {
...@@ -476,10 +488,10 @@ int32_t taosUnLockFile(TdFilePtr pFile) { ...@@ -476,10 +488,10 @@ int32_t taosUnLockFile(TdFilePtr pFile) {
} }
int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
if (pFile->fd < 0) { if (pFile->fd < 0) {
errno = EBADF; errno = EBADF;
uError("%s\n", "fd arg was negative"); printf("%s\n", "fd arg was negative");
return -1; return -1;
} }
...@@ -489,7 +501,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { ...@@ -489,7 +501,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
li_0.QuadPart = (int64_t)0; li_0.QuadPart = (int64_t)0;
BOOL cur = SetFilePointerEx(h, li_0, NULL, FILE_CURRENT); BOOL cur = SetFilePointerEx(h, li_0, NULL, FILE_CURRENT);
if (!cur) { if (!cur) {
uError("SetFilePointerEx Error getting current position in file.\n"); printf("SetFilePointerEx Error getting current position in file.\n");
return -1; return -1;
} }
...@@ -498,7 +510,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { ...@@ -498,7 +510,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
BOOL cur2 = SetFilePointerEx(h, li_size, NULL, FILE_BEGIN); BOOL cur2 = SetFilePointerEx(h, li_size, NULL, FILE_BEGIN);
if (cur2 == 0) { if (cur2 == 0) {
int error = GetLastError(); int error = GetLastError();
uError("SetFilePointerEx GetLastError is: %d\n", error); printf("SetFilePointerEx GetLastError is: %d\n", error);
switch (error) { switch (error) {
case ERROR_INVALID_HANDLE: case ERROR_INVALID_HANDLE:
errno = EBADF; errno = EBADF;
...@@ -512,7 +524,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { ...@@ -512,7 +524,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
if (!SetEndOfFile(h)) { if (!SetEndOfFile(h)) {
int error = GetLastError(); int error = GetLastError();
uError("SetEndOfFile GetLastError is:%d", error); printf("SetEndOfFile GetLastError is:%d", error);
switch (error) { switch (error) {
case ERROR_INVALID_HANDLE: case ERROR_INVALID_HANDLE:
errno = EBADF; errno = EBADF;
...@@ -536,10 +548,10 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { ...@@ -536,10 +548,10 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
} }
int32_t taosFsyncFile(TdFilePtr pFile) { int32_t taosFsyncFile(TdFilePtr pFile) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
if (pFile->fd < 0) { if (pFile->fd < 0) {
errno = EBADF; errno = EBADF;
uError("%s\n", "fd arg was negative"); printf("%s\n", "fd arg was negative");
return -1; return -1;
} }
...@@ -558,84 +570,51 @@ int32_t taosFsyncFile(TdFilePtr pFile) { ...@@ -558,84 +570,51 @@ int32_t taosFsyncFile(TdFilePtr pFile) {
#endif #endif
} }
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size) {
if (pFileOut == NULL || pFileIn == NULL) {
#define _SEND_FILE_STEP_ 1000 return 0;
int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t count) {
fseek(in_file, (int32_t)(*offset), 0);
int64_t writeLen = 0;
uint8_t buffer[_SEND_FILE_STEP_] = {0};
for (int64_t len = 0; len < (count - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) {
size_t rlen = fread(buffer, 1, _SEND_FILE_STEP_, in_file);
if (rlen <= 0) {
return writeLen;
} else if (rlen < _SEND_FILE_STEP_) {
fwrite(buffer, 1, rlen, out_file);
return (int64_t)(writeLen + rlen);
} else {
fwrite(buffer, 1, _SEND_FILE_STEP_, in_file);
writeLen += _SEND_FILE_STEP_;
}
}
int64_t remain = count - writeLen;
if (remain > 0) {
size_t rlen = fread(buffer, 1, (size_t)remain, in_file);
if (rlen <= 0) {
return writeLen;
} else {
fwrite(buffer, 1, (size_t)remain, out_file);
writeLen += remain;
}
} }
assert(pFileIn->fd >= 0 && pFileOut->fd >= 0);
return writeLen; #ifdef WINDOWS
}
int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t count) {
if (offset != NULL) lseek(sfd, (int32_t)(*offset), 0);
lseek(pFileIn->fd, (int32_t)(*offset), 0);
int64_t writeLen = 0; int64_t writeLen = 0;
uint8_t buffer[_SEND_FILE_STEP_] = {0}; uint8_t buffer[_SEND_FILE_STEP_] = {0};
for (int64_t len = 0; len < (count - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) { for (int64_t len = 0; len < (size - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) {
int32_t rlen = (int32_t)read(sfd, buffer, _SEND_FILE_STEP_); size_t rlen = read(pFileIn->fd, (void *)buffer, _SEND_FILE_STEP_);
if (rlen <= 0) { if (rlen <= 0) {
return writeLen; return writeLen;
} else if (rlen < _SEND_FILE_STEP_) { } else if (rlen < _SEND_FILE_STEP_) {
taosWriteSocket(dfd, buffer, rlen); write(pFileOut->fd, (void *)buffer, (uint32_t)rlen);
return (int64_t)(writeLen + rlen); return (int64_t)(writeLen + rlen);
} else { } else {
taosWriteSocket(dfd, buffer, _SEND_FILE_STEP_); write(pFileOut->fd, (void *)buffer, _SEND_FILE_STEP_);
writeLen += _SEND_FILE_STEP_; writeLen += _SEND_FILE_STEP_;
} }
} }
int64_t remain = count - writeLen; int64_t remain = size - writeLen;
if (remain > 0) { if (remain > 0) {
int32_t rlen = read(sfd, buffer, (int32_t)remain); size_t rlen = read(pFileIn->fd, (void *)buffer, (size_t)remain);
if (rlen <= 0) { if (rlen <= 0) {
return writeLen; return writeLen;
} else { } else {
taosWriteSocket(sfd, buffer, (int32_t)remain); write(pFileOut->fd, (void *)buffer, (uint32_t)remain);
writeLen += remain; writeLen += remain;
} }
} }
return writeLen; return writeLen;
}
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t count) {
int r = 0; int r = 0;
if (offset) { if (offset) {
r = fseek(in_file, *offset, SEEK_SET); r = fseek(in_file, *offset, SEEK_SET);
if (r == -1) return -1; if (r == -1) return -1;
} }
off_t len = count; off_t len = size;
while (len > 0) { while (len > 0) {
char buf[1024 * 16]; char buf[1024 * 16];
off_t n = sizeof(buf); off_t n = sizeof(buf);
...@@ -651,64 +630,10 @@ int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t co ...@@ -651,64 +630,10 @@ int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t co
} }
len -= m; len -= m;
} }
return count - len; return size - len;
}
int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t count) {
int r = 0;
if (offset) {
r = lseek(sfd, *offset, SEEK_SET);
if (r == -1) return -1;
}
off_t len = count;
while (len > 0) {
char buf[1024 * 16];
off_t n = sizeof(buf);
if (len < n) n = len;
size_t m = read(sfd, buf, n);
if (m == -1) return -1;
if (m == 0) break;
size_t l = write(dfd, buf, m);
if (l == -1) return -1;
len -= l;
}
return count - len;
}
#else #else
// int64_t taosSendFile(int fdDst, TdFilePtr pFileSrc, int64_t *offset, int64_t size) {
// if (pFileSrc == NULL) {
// return 0;
// }
// assert(pFileSrc->fd >= 0);
// int64_t leftbytes = size;
// int64_t sentbytes;
// while (leftbytes > 0) {
// sentbytes = sendfile(fdDst, pFileSrc->fd, offset, leftbytes);
// if (sentbytes == -1) {
// if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
// continue;
// } else {
// return -1;
// }
// } else if (sentbytes == 0) {
// return (int64_t)(size - leftbytes);
// }
// leftbytes -= sentbytes;
// }
// return size;
// }
int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size) {
if (pFileOut == NULL || pFileIn == NULL) {
return 0;
}
assert(pFileIn->fd >= 0 && pFileOut->fd >= 0);
int64_t leftbytes = size; int64_t leftbytes = size;
int64_t sentbytes; int64_t sentbytes;
...@@ -728,9 +653,8 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in ...@@ -728,9 +653,8 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
} }
return size; return size;
}
#endif #endif
}
void taosFprintfFile(TdFilePtr pFile, const char *format, ...) { void taosFprintfFile(TdFilePtr pFile, const char *format, ...) {
if (pFile == NULL) { if (pFile == NULL) {
...@@ -745,22 +669,10 @@ void taosFprintfFile(TdFilePtr pFile, const char *format, ...) { ...@@ -745,22 +669,10 @@ void taosFprintfFile(TdFilePtr pFile, const char *format, ...) {
fflush(pFile->fp); fflush(pFile->fp);
} }
#if !defined(WINDOWS)
void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) {
if (pFile == NULL) {
return NULL;
}
assert(pFile->fd >= 0); // Please check if you have closed the file.
void *ptr = mmap(NULL, length, PROT_READ, MAP_SHARED, pFile->fd, 0);
return ptr;
}
#endif
bool taosValidFile(TdFilePtr pFile) { return pFile != NULL; } bool taosValidFile(TdFilePtr pFile) { return pFile != NULL; }
int32_t taosUmaskFile(int32_t maskVal) { int32_t taosUmaskFile(int32_t maskVal) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return 0; return 0;
#else #else
return umask(maskVal); return umask(maskVal);
...@@ -769,16 +681,26 @@ int32_t taosUmaskFile(int32_t maskVal) { ...@@ -769,16 +681,26 @@ int32_t taosUmaskFile(int32_t maskVal) {
int32_t taosGetErrorFile(TdFilePtr pFile) { return errno; } int32_t taosGetErrorFile(TdFilePtr pFile) { return errno; }
int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) { int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) {
if (pFile == NULL) { if (pFile == NULL || ptrBuf == NULL ) {
return -1; return -1;
} }
if (*ptrBuf != NULL) { if (*ptrBuf != NULL) {
taosMemoryFreeClear(*ptrBuf); taosMemoryFreeClear(*ptrBuf);
} }
assert(pFile->fp != NULL); assert(pFile->fp != NULL);
#ifdef WINDOWS
*ptrBuf = taosMemoryMalloc(1024);
if (*ptrBuf == NULL) return -1;
if (fgets(*ptrBuf, 1023, pFile->fp) == NULL) {
taosMemoryFreeClear(*ptrBuf);
return -1;
}
(*ptrBuf)[1023] = 0;
return strlen(*ptrBuf);
#else
size_t len = 0; size_t len = 0;
return getline(ptrBuf, &len, pFile->fp); return getline(ptrBuf, &len, pFile->fp);
#endif
} }
int32_t taosEOFFile(TdFilePtr pFile) { int32_t taosEOFFile(TdFilePtr pFile) {
if (pFile == NULL) { if (pFile == NULL) {
...@@ -789,8 +711,6 @@ int32_t taosEOFFile(TdFilePtr pFile) { ...@@ -789,8 +711,6 @@ int32_t taosEOFFile(TdFilePtr pFile) {
return feof(pFile->fp); return feof(pFile->fp);
} }
#if !defined(WINDOWS)
bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) { bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) {
int flags = 0; int flags = 0;
...@@ -805,10 +725,11 @@ bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) { ...@@ -805,10 +725,11 @@ bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) {
if (tdFileAccessOptions & TD_FILE_ACCESS_WRITE_OK) { if (tdFileAccessOptions & TD_FILE_ACCESS_WRITE_OK) {
flags |= W_OK; flags |= W_OK;
} }
#ifdef WINDOWS
return _access(pathname, flags) == 0;
#else
return access(pathname, flags) == 0; return access(pathname, flags) == 0;
#endif
} }
bool taosCheckExistFile(const char *pathname) { return taosCheckAccessFile(pathname, TD_FILE_ACCESS_EXIST_OK); }; bool taosCheckExistFile(const char *pathname) { return taosCheckAccessFile(pathname, TD_FILE_ACCESS_EXIST_OK); };
#endif // WINDOWS
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "osLocale.h" #include "osLocale.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#if (_WIN64) #if (_WIN64)
#include <iphlpapi.h> #include <iphlpapi.h>
#include <mswsock.h> #include <mswsock.h>
...@@ -87,7 +87,7 @@ void taosSetSystemLocale(const char *inLocale, const char *inCharSet) { ...@@ -87,7 +87,7 @@ void taosSetSystemLocale(const char *inLocale, const char *inCharSet) {
} }
void taosGetSystemLocale(char *outLocale, char *outCharset) { void taosGetSystemLocale(char *outLocale, char *outCharset) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
char *locale = setlocale(LC_CTYPE, "chs"); char *locale = setlocale(LC_CTYPE, "chs");
if (locale != NULL) { if (locale != NULL) {
tstrncpy(outLocale, locale, TD_LOCALE_LEN); tstrncpy(outLocale, locale, TD_LOCALE_LEN);
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
/* /*
* windows implementation * windows implementation
......
...@@ -35,7 +35,7 @@ typedef struct TdMemoryInfo { ...@@ -35,7 +35,7 @@ typedef struct TdMemoryInfo {
// static TdMemoryInfoPtr GlobalMemoryPtr = NULL; // static TdMemoryInfoPtr GlobalMemoryPtr = NULL;
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#define tstrdup(str) _strdup(str) #define tstrdup(str) _strdup(str)
#else #else
#define tstrdup(str) strdup(str) #define tstrdup(str) strdup(str)
...@@ -181,7 +181,11 @@ int32_t taosMemorySize(void *ptr) { ...@@ -181,7 +181,11 @@ int32_t taosMemorySize(void *ptr) {
assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL); assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL);
return pTdMemoryInfo->memorySize; return pTdMemoryInfo->memorySize;
#else
#ifdef WINDOWS
return _msize(ptr);
#else #else
return malloc_usable_size(ptr); return malloc_usable_size(ptr);
#endif #endif
#endif
} }
...@@ -17,9 +17,10 @@ ...@@ -17,9 +17,10 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
char *tsProcPath = NULL;
int32_t taosNewProc(char **args) { int32_t taosNewProc(char **args) {
#ifdef WINDOWS
return 0;
#else
int32_t pid = fork(); int32_t pid = fork();
if (pid == 0) { if (pid == 0) {
args[0] = tsProcPath; args[0] = tsProcPath;
...@@ -30,23 +31,36 @@ int32_t taosNewProc(char **args) { ...@@ -30,23 +31,36 @@ int32_t taosNewProc(char **args) {
} else { } else {
return pid; return pid;
} }
#endif
} }
void taosWaitProc(int32_t pid) { void taosWaitProc(int32_t pid) {
#ifdef WINDOWS
#else
int32_t status = -1; int32_t status = -1;
waitpid(pid, &status, 0); waitpid(pid, &status, 0);
#endif
} }
void taosKillProc(int32_t pid) { kill(pid, SIGINT); } void taosKillProc(int32_t pid) {
#ifdef WINDOWS
#else
kill(pid, SIGINT);
#endif
}
bool taosProcExist(int32_t pid) { bool taosProcExist(int32_t pid) {
#ifdef WINDOWS
return false;
#else
int32_t p = getpgid(pid); int32_t p = getpgid(pid);
return p >= 0; return p >= 0;
#endif
} }
// the length of the new name must be less than the original name to take effect // the length of the new name must be less than the original name to take effect
void taosSetProcName(int32_t argc, char **argv, const char *name) { void taosSetProcName(int32_t argc, char **argv, const char *name) {
prctl(PR_SET_NAME, name); setThreadName(name);
for (int32_t i = 0; i < argc; ++i) { for (int32_t i = 0; i < argc; ++i) {
int32_t len = strlen(argv[i]); int32_t len = strlen(argv[i]);
......
...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
#define ALLOW_FORBID_FUNC #define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#include "windows.h"
#include "wincrypt.h"
#else #else
#include <sys/file.h> #include <sys/file.h>
#include <unistd.h> #include <unistd.h>
...@@ -25,9 +27,25 @@ void taosSeedRand(uint32_t seed) { return srand(seed); } ...@@ -25,9 +27,25 @@ void taosSeedRand(uint32_t seed) { return srand(seed); }
uint32_t taosRand(void) { return rand(); } uint32_t taosRand(void) { return rand(); }
uint32_t taosRandR(uint32_t *pSeed) { return rand_r(pSeed); } uint32_t taosRandR(uint32_t *pSeed) {
#ifdef WINDOWS
return rand_s(pSeed);
#else
return rand_r(pSeed);
#endif
}
uint32_t taosSafeRand(void) { uint32_t taosSafeRand(void) {
#ifdef WINDOWS
uint32_t seed;
HCRYPTPROV hCryptProv;
if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, 0)) return seed;
if (hCryptProv != NULL) {
if (!CryptGenRandom(hCryptProv, 4, &seed)) return seed;
}
if (hCryptProv != NULL) CryptReleaseContext(hCryptProv, 0);
return seed;
#else
TdFilePtr pFile; TdFilePtr pFile;
int seed; int seed;
...@@ -43,6 +61,7 @@ uint32_t taosSafeRand(void) { ...@@ -43,6 +61,7 @@ uint32_t taosSafeRand(void) {
} }
return (uint32_t)seed; return (uint32_t)seed;
#endif
} }
void taosRandStr(char* str, int32_t size) { void taosRandStr(char* str, int32_t size) {
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
/* /*
* windows implementation * windows implementation
......
...@@ -22,15 +22,20 @@ ...@@ -22,15 +22,20 @@
static int32_t shmids[MAX_SHMIDS] = {0}; static int32_t shmids[MAX_SHMIDS] = {0};
static void taosDeleteCreatedShms() { static void taosDeleteCreatedShms() {
#if defined(WINDOWS)
#else
for (int32_t i = 0; i < MAX_SHMIDS; ++i) { for (int32_t i = 0; i < MAX_SHMIDS; ++i) {
int32_t shmid = shmids[i] - 1; int32_t shmid = shmids[i] - 1;
if (shmid >= 0) { if (shmid >= 0) {
shmctl(shmid, IPC_RMID, NULL); shmctl(shmid, IPC_RMID, NULL);
} }
} }
#endif
} }
int32_t taosCreateShm(SShm* pShm, int32_t key, int32_t shmsize) { int32_t taosCreateShm(SShm* pShm, int32_t key, int32_t shmsize) {
#if defined(WINDOWS)
#else
pShm->id = -1; pShm->id = -1;
#if 1 #if 1
...@@ -64,10 +69,13 @@ int32_t taosCreateShm(SShm* pShm, int32_t key, int32_t shmsize) { ...@@ -64,10 +69,13 @@ int32_t taosCreateShm(SShm* pShm, int32_t key, int32_t shmsize) {
shmctl(pShm->id, IPC_RMID, NULL); shmctl(pShm->id, IPC_RMID, NULL);
#endif #endif
#endif
return 0; return 0;
} }
void taosDropShm(SShm* pShm) { void taosDropShm(SShm* pShm) {
#if defined(WINDOWS)
#else
if (pShm->id >= 0) { if (pShm->id >= 0) {
if (pShm->ptr != NULL) { if (pShm->ptr != NULL) {
shmdt(pShm->ptr); shmdt(pShm->ptr);
...@@ -77,14 +85,18 @@ void taosDropShm(SShm* pShm) { ...@@ -77,14 +85,18 @@ void taosDropShm(SShm* pShm) {
pShm->id = -1; pShm->id = -1;
pShm->size = 0; pShm->size = 0;
pShm->ptr = NULL; pShm->ptr = NULL;
#endif
} }
int32_t taosAttachShm(SShm* pShm) { int32_t taosAttachShm(SShm* pShm) {
#if defined(WINDOWS)
#else
errno = 0; errno = 0;
void* ptr = shmat(pShm->id, NULL, 0); void* ptr = shmat(pShm->id, NULL, 0);
if (errno == 0) { if (errno == 0) {
pShm->ptr = ptr; pShm->ptr = ptr;
} }
#endif
return errno; return errno;
} }
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
/* /*
* windows implementation * windows implementation
...@@ -47,6 +47,8 @@ void taosDflSignal(int32_t signum) { ...@@ -47,6 +47,8 @@ void taosDflSignal(int32_t signum) {
signal(signum, SIG_DFL); signal(signum, SIG_DFL);
} }
void taosKillChildOnParentStopped() { }
#else #else
/* /*
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#endif #endif
void taosSsleep(int32_t s) { void taosSsleep(int32_t s) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
Sleep(1000 * s); Sleep(1000 * s);
#else #else
sleep(s); sleep(s);
...@@ -31,7 +31,7 @@ void taosSsleep(int32_t s) { ...@@ -31,7 +31,7 @@ void taosSsleep(int32_t s) {
} }
void taosMsleep(int32_t ms) { void taosMsleep(int32_t ms) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
Sleep(ms); Sleep(ms);
#else #else
usleep(ms * 1000); usleep(ms * 1000);
...@@ -39,8 +39,15 @@ void taosMsleep(int32_t ms) { ...@@ -39,8 +39,15 @@ void taosMsleep(int32_t ms) {
} }
void taosUsleep(int32_t us) { void taosUsleep(int32_t us) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
nanosleep(1000 * us); HANDLE timer;
LARGE_INTEGER interval;
interval.QuadPart = (10 * us);
timer = CreateWaitableTimer(NULL, TRUE, NULL);
SetWaitableTimer(timer, &interval, 0, NULL, NULL, 0);
WaitForSingleObject(timer, INFINITE);
CloseHandle(timer);
#else #else
usleep(us); usleep(us);
#endif #endif
......
...@@ -25,9 +25,6 @@ ...@@ -25,9 +25,6 @@
#include <string.h> #include <string.h>
#include <tchar.h> #include <tchar.h>
#include <winbase.h> #include <winbase.h>
#include <winsock2.h>
#include <ws2def.h>
#include "winsock2.h"
#else #else
#include <arpa/inet.h> #include <arpa/inet.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -68,7 +65,7 @@ int32_t taosSendto(TdSocketPtr pSocket, void *buf, int len, unsigned int flags, ...@@ -68,7 +65,7 @@ int32_t taosSendto(TdSocketPtr pSocket, void *buf, int len, unsigned int flags,
if (pSocket == NULL || pSocket->fd < 0) { if (pSocket == NULL || pSocket->fd < 0) {
return -1; return -1;
} }
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return sendto(pSocket->fd, buf, len, flags, dest_addr, addrlen); return sendto(pSocket->fd, buf, len, flags, dest_addr, addrlen);
#else #else
return sendto(pSocket->fd, buf, len, flags, dest_addr, addrlen); return sendto(pSocket->fd, buf, len, flags, dest_addr, addrlen);
...@@ -78,7 +75,7 @@ int32_t taosWriteSocket(TdSocketPtr pSocket, void *buf, int len) { ...@@ -78,7 +75,7 @@ int32_t taosWriteSocket(TdSocketPtr pSocket, void *buf, int len) {
if (pSocket == NULL || pSocket->fd < 0) { if (pSocket == NULL || pSocket->fd < 0) {
return -1; return -1;
} }
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return send(pSocket->fd, buf, len, 0); return send(pSocket->fd, buf, len, 0);
; ;
#else #else
...@@ -89,7 +86,7 @@ int32_t taosReadSocket(TdSocketPtr pSocket, void *buf, int len) { ...@@ -89,7 +86,7 @@ int32_t taosReadSocket(TdSocketPtr pSocket, void *buf, int len) {
if (pSocket == NULL || pSocket->fd < 0) { if (pSocket == NULL || pSocket->fd < 0) {
return -1; return -1;
} }
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return recv(pSocket->fd, buf, len, 0); return recv(pSocket->fd, buf, len, 0);
; ;
#else #else
...@@ -97,14 +94,14 @@ int32_t taosReadSocket(TdSocketPtr pSocket, void *buf, int len) { ...@@ -97,14 +94,14 @@ int32_t taosReadSocket(TdSocketPtr pSocket, void *buf, int len) {
#endif #endif
} }
int32_t taosReadFromSocket(TdSocketPtr pSocket, void *buf, int32_t len, int32_t flags, struct sockaddr *destAddr, socklen_t *addrLen) { int32_t taosReadFromSocket(TdSocketPtr pSocket, void *buf, int32_t len, int32_t flags, struct sockaddr *destAddr, int *addrLen) {
if (pSocket == NULL || pSocket->fd < 0) { if (pSocket == NULL || pSocket->fd < 0) {
return -1; return -1;
} }
return recvfrom(pSocket->fd, buf, len, flags, destAddr, addrLen); return recvfrom(pSocket->fd, buf, len, flags, destAddr, addrLen);
} }
int32_t taosCloseSocketNoCheck1(SocketFd fd) { int32_t taosCloseSocketNoCheck1(SocketFd fd) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return closesocket(fd); return closesocket(fd);
#else #else
return close(fd); return close(fd);
...@@ -205,8 +202,8 @@ int32_t taosShutDownSocketServerRDWR(TdSocketServerPtr pSocketServer) { ...@@ -205,8 +202,8 @@ int32_t taosShutDownSocketServerRDWR(TdSocketServerPtr pSocketServer) {
#endif #endif
} }
void taosWinSocketInit1() { void taosWinSocketInit() {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
static char flag = 0; static char flag = 0;
if (flag == 0) { if (flag == 0) {
WORD wVersionRequested; WORD wVersionRequested;
...@@ -223,7 +220,7 @@ int32_t taosSetNonblocking(TdSocketPtr pSocket, int32_t on) { ...@@ -223,7 +220,7 @@ int32_t taosSetNonblocking(TdSocketPtr pSocket, int32_t on) {
if (pSocket == NULL || pSocket->fd < 0) { if (pSocket == NULL || pSocket->fd < 0) {
return -1; return -1;
} }
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
u_long mode; u_long mode;
if (on) { if (on) {
mode = 1; mode = 1;
...@@ -255,7 +252,7 @@ int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void ...@@ -255,7 +252,7 @@ int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void
if (pSocket == NULL || pSocket->fd < 0) { if (pSocket == NULL || pSocket->fd < 0) {
return -1; return -1;
} }
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
if (level == SOL_SOCKET && optname == TCP_KEEPCNT) { if (level == SOL_SOCKET && optname == TCP_KEEPCNT) {
return 0; return 0;
} }
...@@ -274,21 +271,21 @@ int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void ...@@ -274,21 +271,21 @@ int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void
return setsockopt(pSocket->fd, level, optname, optval, optlen); return setsockopt(pSocket->fd, level, optname, optval, optlen);
#else #else
return setsockopt(pSocket->fd, level, optname, optval, (socklen_t)optlen); return setsockopt(pSocket->fd, level, optname, optval, (int)optlen);
#endif #endif
} }
int32_t taosGetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t *optlen) { int32_t taosGetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t *optlen) {
if (pSocket == NULL || pSocket->fd < 0) { if (pSocket == NULL || pSocket->fd < 0) {
return -1; return -1;
} }
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return 0; return 0;
#else #else
return getsockopt(pSocket->fd, level, optname, optval, (socklen_t *)optlen); return getsockopt(pSocket->fd, level, optname, optval, (int *)optlen);
#endif #endif
} }
uint32_t taosInetAddr(const char *ipAddr) { uint32_t taosInetAddr(const char *ipAddr) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
uint32_t value; uint32_t value;
int32_t ret = inet_pton(AF_INET, ipAddr, &value); int32_t ret = inet_pton(AF_INET, ipAddr, &value);
if (ret <= 0) { if (ret <= 0) {
...@@ -301,7 +298,7 @@ uint32_t taosInetAddr(const char *ipAddr) { ...@@ -301,7 +298,7 @@ uint32_t taosInetAddr(const char *ipAddr) {
#endif #endif
} }
const char *taosInetNtoa(struct in_addr ipInt) { const char *taosInetNtoa(struct in_addr ipInt) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
// not thread safe, only for debug usage while print log // not thread safe, only for debug usage while print log
static char tmpDstStr[16]; static char tmpDstStr[16];
return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN); return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN);
...@@ -693,7 +690,7 @@ TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port) { ...@@ -693,7 +690,7 @@ TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port) {
} }
TdSocketPtr taosAcceptTcpConnectSocket(TdSocketServerPtr pServerSocket, struct sockaddr *destAddr, TdSocketPtr taosAcceptTcpConnectSocket(TdSocketServerPtr pServerSocket, struct sockaddr *destAddr,
socklen_t *addrLen) { int *addrLen) {
if (pServerSocket == NULL || pServerSocket->fd < 0) { if (pServerSocket == NULL || pServerSocket->fd < 0) {
return NULL; return NULL;
} }
...@@ -753,12 +750,12 @@ int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len ...@@ -753,12 +750,12 @@ int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len
} }
void taosBlockSIGPIPE() { void taosBlockSIGPIPE() {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#else #else
sigset_t signal_mask; sigset_t signal_mask;
sigemptyset(&signal_mask); sigemptyset(&signal_mask);
sigaddset(&signal_mask, SIGPIPE); sigaddset(&signal_mask, SIGPIPE);
int32_t rc = taosThreadSigMask(SIG_BLOCK, &signal_mask, NULL); int32_t rc = pthread_sigmask(SIG_BLOCK, &signal_mask, NULL);
if (rc != 0) { if (rc != 0) {
// printf("failed to block SIGPIPE"); // printf("failed to block SIGPIPE");
} }
...@@ -864,26 +861,26 @@ void tinet_ntoa(char *ipstr, uint32_t ip) { ...@@ -864,26 +861,26 @@ void tinet_ntoa(char *ipstr, uint32_t ip) {
} }
void taosIgnSIGPIPE() { void taosIgnSIGPIPE() {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#else #else
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
#endif #endif
} }
void taosSetMaskSIGPIPE() { void taosSetMaskSIGPIPE() {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#else #else
sigset_t signal_mask; sigset_t signal_mask;
sigemptyset(&signal_mask); sigemptyset(&signal_mask);
sigaddset(&signal_mask, SIGPIPE); sigaddset(&signal_mask, SIGPIPE);
int32_t rc = taosThreadSigMask(SIG_SETMASK, &signal_mask, NULL); int32_t rc = pthread_sigmask(SIG_SETMASK, &signal_mask, NULL);
if (rc != 0) { if (rc != 0) {
// printf("failed to setmask SIGPIPE"); // printf("failed to setmask SIGPIPE");
} }
#endif #endif
} }
int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, socklen_t *addrLen) { int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *addrLen) {
if (pSocket == NULL || pSocket->fd < 0) { if (pSocket == NULL || pSocket->fd < 0) {
return -1; return -1;
} }
...@@ -893,7 +890,7 @@ int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, sockle ...@@ -893,7 +890,7 @@ int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, sockle
TdEpollPtr taosCreateEpoll(int32_t size) { TdEpollPtr taosCreateEpoll(int32_t size) {
EpollFd fd = -1; EpollFd fd = -1;
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#else #else
fd = epoll_create(size); fd = epoll_create(size);
#endif #endif
...@@ -915,7 +912,7 @@ int32_t taosCtlEpoll(TdEpollPtr pEpoll, int32_t epollOperate, TdSocketPtr pSocke ...@@ -915,7 +912,7 @@ int32_t taosCtlEpoll(TdEpollPtr pEpoll, int32_t epollOperate, TdSocketPtr pSocke
if (pEpoll == NULL || pEpoll->fd < 0) { if (pEpoll == NULL || pEpoll->fd < 0) {
return -1; return -1;
} }
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#else #else
code = epoll_ctl(pEpoll->fd, epollOperate, pSocket->fd, event); code = epoll_ctl(pEpoll->fd, epollOperate, pSocket->fd, event);
#endif #endif
...@@ -926,7 +923,7 @@ int32_t taosWaitEpoll(TdEpollPtr pEpoll, struct epoll_event *event, int32_t maxE ...@@ -926,7 +923,7 @@ int32_t taosWaitEpoll(TdEpollPtr pEpoll, struct epoll_event *event, int32_t maxE
if (pEpoll == NULL || pEpoll->fd < 0) { if (pEpoll == NULL || pEpoll->fd < 0) {
return -1; return -1;
} }
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#else #else
code = epoll_wait(pEpoll->fd, event, maxEvents, timeout); code = epoll_wait(pEpoll->fd, event, maxEvents, timeout);
#endif #endif
......
...@@ -24,6 +24,55 @@ ...@@ -24,6 +24,55 @@
extern int wcwidth(wchar_t c); extern int wcwidth(wchar_t c);
extern int wcswidth(const wchar_t *s, size_t n); extern int wcswidth(const wchar_t *s, size_t n);
#ifdef WINDOWS
char *strsep(char **stringp, const char *delim) {
char * s;
const char *spanp;
int32_t c, sc;
char *tok;
if ((s = *stringp) == NULL)
return (NULL);
for (tok = s;;) {
c = *s++;
spanp = delim;
do {
if ((sc = *spanp++) == c) {
if (c == 0)
s = NULL;
else
s[-1] = 0;
*stringp = s;
return (tok);
}
} while (sc != 0);
}
/* NOTREACHED */
}
/* Duplicate a string, up to at most size characters */
char *strndup(const char *s, size_t size) {
size_t l;
char *s2;
l = strlen(s);
if (l > size) l=size;
s2 = malloc(l+1);
if (s2) {
strncpy(s2, s, l);
s2[l] = '\0';
}
return s2;
}
/* Copy no more than N characters of SRC to DEST, returning the address of
the terminating '\0' in DEST, if any, or else DEST + N. */
char *stpncpy (char *dest, const char *src, size_t n) {
size_t size = strnlen (src, n);
memcpy (dest, src, size);
dest += size;
if (size == n)
return dest;
return memset (dest, '\0', n - size);
}
#endif
int64_t taosStr2int64(const char *str) { int64_t taosStr2int64(const char *str) {
char *endptr = NULL; char *endptr = NULL;
return strtoll(str, &endptr, 10); return strtoll(str, &endptr, 10);
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
// //
//#include "lukemftp.h" //#include "lukemftp.h"
// #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) // #ifdef WINDOWS
// #include <time.h> // #include <time.h>
// #include <stdlib.h> // #include <stdlib.h>
...@@ -100,7 +100,7 @@ ...@@ -100,7 +100,7 @@
// #endif // #endif
// char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) { // char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) {
// #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) // #ifdef WINDOWS
// char c; // char c;
// const char *bp; // const char *bp;
// size_t len = 0; // size_t len = 0;
......
...@@ -17,7 +17,23 @@ ...@@ -17,7 +17,23 @@
#include "os.h" #include "os.h"
#include "taoserror.h" #include "taoserror.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #define PROCESS_ITEM 12
typedef struct {
uint64_t user;
uint64_t nice;
uint64_t system;
uint64_t idle;
} SysCpuInfo;
typedef struct {
uint64_t utime; // user time
uint64_t stime; // kernel time
uint64_t cutime; // all user time
uint64_t cstime; // all dead time
} ProcCpuInfo;
#ifdef WINDOWS
/* /*
* windows implementation * windows implementation
...@@ -92,22 +108,6 @@ LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) { ...@@ -92,22 +108,6 @@ LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) {
#include <sys/utsname.h> #include <sys/utsname.h>
#include <unistd.h> #include <unistd.h>
#define PROCESS_ITEM 12
typedef struct {
uint64_t user;
uint64_t nice;
uint64_t system;
uint64_t idle;
} SysCpuInfo;
typedef struct {
uint64_t utime; // user time
uint64_t stime; // kernel time
uint64_t cutime; // all user time
uint64_t cstime; // all dead time
} ProcCpuInfo;
static pid_t tsProcId; static pid_t tsProcId;
static char tsSysNetFile[] = "/proc/net/dev"; static char tsSysNetFile[] = "/proc/net/dev";
static char tsSysCpuFile[] = "/proc/stat"; static char tsSysCpuFile[] = "/proc/stat";
...@@ -125,8 +125,12 @@ static void taosGetProcIOnfos() { ...@@ -125,8 +125,12 @@ static void taosGetProcIOnfos() {
snprintf(tsProcCpuFile, sizeof(tsProcCpuFile), "/proc/%d/stat", tsProcId); snprintf(tsProcCpuFile, sizeof(tsProcCpuFile), "/proc/%d/stat", tsProcId);
snprintf(tsProcIOFile, sizeof(tsProcIOFile), "/proc/%d/io", tsProcId); snprintf(tsProcIOFile, sizeof(tsProcIOFile), "/proc/%d/io", tsProcId);
} }
#endif
static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
#ifdef WINDOWS
#elif defined(_TD_DARWIN_64)
#else
TdFilePtr pFile = taosOpenFile(tsSysCpuFile, TD_FILE_READ | TD_FILE_STREAM); TdFilePtr pFile = taosOpenFile(tsSysCpuFile, TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) { if (pFile == NULL) {
return -1; return -1;
...@@ -145,10 +149,14 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { ...@@ -145,10 +149,14 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
if (line != NULL) taosMemoryFreeClear(line); if (line != NULL) taosMemoryFreeClear(line);
taosCloseFile(&pFile); taosCloseFile(&pFile);
#endif
return 0; return 0;
} }
static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
#ifdef WINDOWS
#elif defined(_TD_DARWIN_64)
#else
TdFilePtr pFile = taosOpenFile(tsProcCpuFile, TD_FILE_READ | TD_FILE_STREAM); TdFilePtr pFile = taosOpenFile(tsProcCpuFile, TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) { if (pFile == NULL) {
return -1; return -1;
...@@ -172,10 +180,10 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { ...@@ -172,10 +180,10 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
if (line != NULL) taosMemoryFreeClear(line); if (line != NULL) taosMemoryFreeClear(line);
taosCloseFile(&pFile); taosCloseFile(&pFile);
#endif
return 0; return 0;
} }
#endif
bool taosCheckSystemIsSmallEnd() { bool taosCheckSystemIsSmallEnd() {
union check { union check {
...@@ -187,7 +195,7 @@ bool taosCheckSystemIsSmallEnd() { ...@@ -187,7 +195,7 @@ bool taosCheckSystemIsSmallEnd() {
} }
void taosGetSystemInfo() { void taosGetSystemInfo() {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
taosGetCpuCores(&tsNumOfCores); taosGetCpuCores(&tsNumOfCores);
taosGetTotalMemory(&tsTotalMemoryKB); taosGetTotalMemory(&tsTotalMemoryKB);
...@@ -210,7 +218,7 @@ void taosGetSystemInfo() { ...@@ -210,7 +218,7 @@ void taosGetSystemInfo() {
} }
int32_t taosGetEmail(char *email, int32_t maxLen) { int32_t taosGetEmail(char *email, int32_t maxLen) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
const char *filepath = "/usr/local/taos/email"; const char *filepath = "/usr/local/taos/email";
...@@ -241,7 +249,7 @@ int32_t taosGetEmail(char *email, int32_t maxLen) { ...@@ -241,7 +249,7 @@ int32_t taosGetEmail(char *email, int32_t maxLen) {
} }
int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) { int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
char *line = NULL; char *line = NULL;
size_t size = 0; size_t size = 0;
...@@ -296,7 +304,7 @@ int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) { ...@@ -296,7 +304,7 @@ int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) {
} }
int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
char *line = NULL; char *line = NULL;
size_t size = 0; size_t size = 0;
...@@ -355,7 +363,7 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { ...@@ -355,7 +363,7 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
} }
int32_t taosGetCpuCores(float *numOfCores) { int32_t taosGetCpuCores(float *numOfCores) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
SYSTEM_INFO info; SYSTEM_INFO info;
GetSystemInfo(&info); GetSystemInfo(&info);
*numOfCores = info.dwNumberOfProcessors; *numOfCores = info.dwNumberOfProcessors;
...@@ -399,7 +407,7 @@ void taosGetCpuUsage(double *cpu_system, double *cpu_engine) { ...@@ -399,7 +407,7 @@ void taosGetCpuUsage(double *cpu_system, double *cpu_engine) {
} }
int32_t taosGetTotalMemory(int64_t *totalKB) { int32_t taosGetTotalMemory(int64_t *totalKB) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
MEMORYSTATUSEX memsStat; MEMORYSTATUSEX memsStat;
memsStat.dwLength = sizeof(memsStat); memsStat.dwLength = sizeof(memsStat);
if (!GlobalMemoryStatusEx(&memsStat)) { if (!GlobalMemoryStatusEx(&memsStat)) {
...@@ -417,7 +425,7 @@ int32_t taosGetTotalMemory(int64_t *totalKB) { ...@@ -417,7 +425,7 @@ int32_t taosGetTotalMemory(int64_t *totalKB) {
} }
int32_t taosGetProcMemory(int64_t *usedKB) { int32_t taosGetProcMemory(int64_t *usedKB) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
unsigned bytes_used = 0; unsigned bytes_used = 0;
#if defined(_WIN64) && defined(_MSC_VER) #if defined(_WIN64) && defined(_MSC_VER)
...@@ -469,7 +477,7 @@ int32_t taosGetProcMemory(int64_t *usedKB) { ...@@ -469,7 +477,7 @@ int32_t taosGetProcMemory(int64_t *usedKB) {
} }
int32_t taosGetSysMemory(int64_t *usedKB) { int32_t taosGetSysMemory(int64_t *usedKB) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
MEMORYSTATUSEX memsStat; MEMORYSTATUSEX memsStat;
memsStat.dwLength = sizeof(memsStat); memsStat.dwLength = sizeof(memsStat);
if (!GlobalMemoryStatusEx(&memsStat)) { if (!GlobalMemoryStatusEx(&memsStat)) {
...@@ -534,7 +542,7 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { ...@@ -534,7 +542,7 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
} }
int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
IO_COUNTERS io_counter; IO_COUNTERS io_counter;
if (GetProcessIoCounters(GetCurrentProcess(), &io_counter)) { if (GetProcessIoCounters(GetCurrentProcess(), &io_counter)) {
if (rchars) *rchars = io_counter.ReadTransferCount; if (rchars) *rchars = io_counter.ReadTransferCount;
...@@ -620,7 +628,7 @@ void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, i ...@@ -620,7 +628,7 @@ void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, i
} }
int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
*receive_bytes = 0; *receive_bytes = 0;
*transmit_bytes = 0; *transmit_bytes = 0;
return 0; return 0;
...@@ -691,7 +699,7 @@ void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { ...@@ -691,7 +699,7 @@ void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) {
} }
void taosKillSystem() { void taosKillSystem() {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
printf("function taosKillSystem, exit!"); printf("function taosKillSystem, exit!");
exit(0); exit(0);
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
...@@ -705,7 +713,7 @@ void taosKillSystem() { ...@@ -705,7 +713,7 @@ void taosKillSystem() {
} }
int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { int32_t taosGetSystemUUID(char *uid, int32_t uidlen) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
GUID guid; GUID guid;
CoCreateGuid(&guid); CoCreateGuid(&guid);
...@@ -741,7 +749,7 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { ...@@ -741,7 +749,7 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) {
} }
char *taosGetCmdlineByPID(int pid) { char *taosGetCmdlineByPID(int pid) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
return ""; return "";
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
static char cmdline[1024]; static char cmdline[1024];
...@@ -777,7 +785,7 @@ char *taosGetCmdlineByPID(int pid) { ...@@ -777,7 +785,7 @@ char *taosGetCmdlineByPID(int pid) {
} }
void taosSetCoreDump(bool enable) { void taosSetCoreDump(bool enable) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
SetUnhandledExceptionFilter(&FlCrashDump); SetUnhandledExceptionFilter(&FlCrashDump);
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
#else #else
...@@ -857,7 +865,7 @@ void taosSetCoreDump(bool enable) { ...@@ -857,7 +865,7 @@ void taosSetCoreDump(bool enable) {
} }
SysNameInfo taosGetSysNameInfo() { SysNameInfo taosGetSysNameInfo() {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
SysNameInfo info = {0}; SysNameInfo info = {0};
......
...@@ -183,16 +183,33 @@ void resetTerminalMode() { ...@@ -183,16 +183,33 @@ void resetTerminalMode() {
TdCmdPtr taosOpenCmd(const char *cmd) { TdCmdPtr taosOpenCmd(const char *cmd) {
if (cmd == NULL) return NULL; if (cmd == NULL) return NULL;
#ifdef WINDOWS
return (TdCmdPtr)_popen(cmd, "r");
#else
return (TdCmdPtr)popen(cmd, "r"); return (TdCmdPtr)popen(cmd, "r");
#endif
} }
int64_t taosGetLineCmd(TdCmdPtr pCmd, char ** __restrict ptrBuf) { int64_t taosGetLineCmd(TdCmdPtr pCmd, char ** __restrict ptrBuf) {
if (pCmd == NULL) { if (pCmd == NULL || ptrBuf == NULL ) {
return -1; return -1;
} }
if (*ptrBuf != NULL) {
taosMemoryFreeClear(*ptrBuf);
}
#ifdef WINDOWS
*ptrBuf = taosMemoryMalloc(1024);
if (*ptrBuf == NULL) return -1;
if (fgets(*ptrBuf, 1023, (FILE*)pCmd) == NULL) {
taosMemoryFreeClear(*ptrBuf);
return -1;
}
(*ptrBuf)[1023] = 0;
return strlen(*ptrBuf);
#else
size_t len = 0; size_t len = 0;
return getline(ptrBuf, &len, (FILE*)pCmd); return getline(ptrBuf, &len, (FILE*)pCmd);
#endif
} }
int32_t taosEOFCmd(TdCmdPtr pCmd) { int32_t taosEOFCmd(TdCmdPtr pCmd) {
...@@ -206,7 +223,11 @@ int64_t taosCloseCmd(TdCmdPtr *ppCmd) { ...@@ -206,7 +223,11 @@ int64_t taosCloseCmd(TdCmdPtr *ppCmd) {
if (ppCmd == NULL || *ppCmd == NULL) { if (ppCmd == NULL || *ppCmd == NULL) {
return 0; return 0;
} }
#ifdef WINDOWS
_pclose((FILE*)(*ppCmd));
#else
pclose((FILE*)(*ppCmd)); pclose((FILE*)(*ppCmd));
#endif
*ppCmd = NULL; *ppCmd = NULL;
return 0; return 0;
} }
...@@ -294,7 +294,7 @@ int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) { ...@@ -294,7 +294,7 @@ int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
} }
int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock) { int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock) {
#ifndef __USE_XOPEN2K #ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_destroy((pthread_mutex_t*)lock); return pthread_mutex_destroy((pthread_mutex_t*)lock);
#else #else
return pthread_spin_destroy((pthread_spinlock_t*)lock); return pthread_spin_destroy((pthread_spinlock_t*)lock);
...@@ -302,15 +302,16 @@ int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock) { ...@@ -302,15 +302,16 @@ int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock) {
} }
int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared) { int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared) {
#ifndef __USE_XOPEN2K #ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_init((pthread_mutex_t*)lock, pshared); assert(pshared == NULL);
return pthread_mutex_init((pthread_mutex_t*)lock, NULL);
#else #else
return pthread_spin_init((pthread_spinlock_t*)lock, pshared); return pthread_spin_init((pthread_spinlock_t*)lock, pshared);
#endif #endif
} }
int32_t taosThreadSpinLock(TdThreadSpinlock * lock) { int32_t taosThreadSpinLock(TdThreadSpinlock * lock) {
#ifndef __USE_XOPEN2K #ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_lock((pthread_mutex_t*)lock); return pthread_mutex_lock((pthread_mutex_t*)lock);
#else #else
return pthread_spin_lock((pthread_spinlock_t*)lock); return pthread_spin_lock((pthread_spinlock_t*)lock);
...@@ -318,7 +319,7 @@ int32_t taosThreadSpinLock(TdThreadSpinlock * lock) { ...@@ -318,7 +319,7 @@ int32_t taosThreadSpinLock(TdThreadSpinlock * lock) {
} }
int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock) { int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock) {
#ifndef __USE_XOPEN2K #ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_trylock((pthread_mutex_t*)lock); return pthread_mutex_trylock((pthread_mutex_t*)lock);
#else #else
return pthread_spin_trylock((pthread_spinlock_t*)lock); return pthread_spin_trylock((pthread_spinlock_t*)lock);
...@@ -326,7 +327,7 @@ int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock) { ...@@ -326,7 +327,7 @@ int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock) {
} }
int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock) { int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock) {
#ifndef __USE_XOPEN2K #ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_unlock((pthread_mutex_t*)lock); return pthread_mutex_unlock((pthread_mutex_t*)lock);
#else #else
return pthread_spin_unlock((pthread_spinlock_t*)lock); return pthread_spin_unlock((pthread_spinlock_t*)lock);
...@@ -337,10 +338,6 @@ void taosThreadTestCancel(void) { ...@@ -337,10 +338,6 @@ void taosThreadTestCancel(void) {
return pthread_testcancel(); return pthread_testcancel();
} }
int32_t taosThreadSigMask(int32_t how, sigset_t const *set, sigset_t * oset) { void taosThreadClear(TdThread *thread) {
return pthread_sigmask(how, set, oset); memset(thread, 0, sizeof(TdThread));
}
int32_t taosThreadSigWait(const sigset_t * set, int32_t *sig) {
return sigwait(set, sig);
} }
\ No newline at end of file
...@@ -26,12 +26,11 @@ ...@@ -26,12 +26,11 @@
#include "os.h" #include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <winsock2.h>
//#define TM_YEAR_BASE 1970 //origin //#define TM_YEAR_BASE 1970 //origin
#define TM_YEAR_BASE 1900 //slguan #define TM_YEAR_BASE 1900 //slguan
/* /*
...@@ -85,13 +84,43 @@ static const char *am_pm[2] = { ...@@ -85,13 +84,43 @@ static const char *am_pm[2] = {
"AM", "PM" "AM", "PM"
}; };
#define BILLION (1E9)
static BOOL g_first_time = 1;
static LARGE_INTEGER g_counts_per_sec;
int clock_gettime(int dummy, struct timespec *ct)
{
LARGE_INTEGER count;
if (g_first_time)
{
g_first_time = 0;
if (0 == QueryPerformanceFrequency(&g_counts_per_sec))
{
g_counts_per_sec.QuadPart = 0;
}
}
if ((NULL == ct) || (g_counts_per_sec.QuadPart <= 0) ||
(0 == QueryPerformanceCounter(&count)))
{
return -1;
}
ct->tv_sec = count.QuadPart / g_counts_per_sec.QuadPart;
ct->tv_nsec = ((count.QuadPart % g_counts_per_sec.QuadPart) * BILLION) / g_counts_per_sec.QuadPart;
return 0;
}
#else #else
#include <sys/time.h> #include <sys/time.h>
#endif #endif
char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) { char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
char c; char c;
const char *bp; const char *bp;
size_t len = 0; size_t len = 0;
...@@ -391,7 +420,7 @@ char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) { ...@@ -391,7 +420,7 @@ char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) {
} }
FORCE_INLINE int32_t taosGetTimeOfDay(struct timeval *tv) { FORCE_INLINE int32_t taosGetTimeOfDay(struct timeval *tv) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
time_t t; time_t t;
t = taosGetTimestampSec(); t = taosGetTimestampSec();
SYSTEMTIME st; SYSTEMTIME st;
...@@ -418,7 +447,7 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result) { ...@@ -418,7 +447,7 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result) {
if (result == NULL) { if (result == NULL) {
return localtime(timep); return localtime(timep);
} }
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifdef WINDOWS
localtime_s(result, timep); localtime_s(result, timep);
#else #else
localtime_r(timep, result); localtime_r(timep, result);
...@@ -427,3 +456,5 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result) { ...@@ -427,3 +456,5 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result) {
} }
int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } int32_t taosGetTimestampSec() { return (int32_t)time(NULL); }
int32_t taosClockGetTime(int clock_id, struct timespec *pTS) { return clock_gettime(clock_id, pTS); }
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册