未验证 提交 73267640 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #6045 from taosdata/feature/cp

Feature/cp
......@@ -57,7 +57,7 @@ IF (TD_LINUX_64)
ADD_DEFINITIONS(-D_M_X64)
ADD_DEFINITIONS(-D_TD_LINUX_64)
MESSAGE(STATUS "linux64 is defined")
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
SET(COMMON_FLAGS "-Wall -Werror -fPIC -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
ADD_DEFINITIONS(-DUSE_LIBICONV)
ENDIF ()
......@@ -65,7 +65,7 @@ IF (TD_LINUX_32)
ADD_DEFINITIONS(-D_TD_LINUX_32)
ADD_DEFINITIONS(-DUSE_LIBICONV)
MESSAGE(STATUS "linux32 is defined")
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -munaligned-access -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -munaligned-access -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
ENDIF ()
IF (TD_ARM_64)
......@@ -73,7 +73,7 @@ IF (TD_ARM_64)
ADD_DEFINITIONS(-D_TD_ARM_)
ADD_DEFINITIONS(-DUSE_LIBICONV)
MESSAGE(STATUS "arm64 is defined")
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
ENDIF ()
IF (TD_ARM_32)
......@@ -81,7 +81,7 @@ IF (TD_ARM_32)
ADD_DEFINITIONS(-D_TD_ARM_)
ADD_DEFINITIONS(-DUSE_LIBICONV)
MESSAGE(STATUS "arm32 is defined")
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types ")
SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types ")
ENDIF ()
IF (TD_MIPS_64)
......@@ -89,7 +89,7 @@ IF (TD_MIPS_64)
ADD_DEFINITIONS(-D_TD_MIPS_64)
ADD_DEFINITIONS(-DUSE_LIBICONV)
MESSAGE(STATUS "mips64 is defined")
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
ENDIF ()
IF (TD_MIPS_32)
......@@ -97,7 +97,7 @@ IF (TD_MIPS_32)
ADD_DEFINITIONS(-D_TD_MIPS_32)
ADD_DEFINITIONS(-DUSE_LIBICONV)
MESSAGE(STATUS "mips32 is defined")
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
SET(COMMON_FLAGS "-Wall -Werror -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
ENDIF ()
IF (TD_APLHINE)
......@@ -138,7 +138,7 @@ IF (TD_DARWIN_64)
ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
ADD_DEFINITIONS(-DUSE_LIBICONV)
MESSAGE(STATUS "darwin64 is defined")
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
SET(COMMON_FLAGS "-Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG")
SET(RELEASE_FLAGS "-Og")
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
......
......@@ -32,6 +32,7 @@ ENDIF ()
#
# Set compiler options
SET(COMMON_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COMMON_FLAGS} ${DEBUG_FLAGS}")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${COMMON_FLAGS} ${RELEASE_FLAGS}")
......
......@@ -68,7 +68,7 @@ int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int1
} else if (strncmp(pToken->z, "0", 1) == 0 && pToken->n == 1) {
// do nothing
} else if (pToken->type == TK_INTEGER) {
useconds = tsosStr2int64(pToken->z);
useconds = taosStr2int64(pToken->z);
} else {
// strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);
if (taosParseTime(pToken->z, time, pToken->n, timePrec, tsDaylight) != TSDB_CODE_SUCCESS) {
......
......@@ -158,7 +158,7 @@ static int32_t dnodeWriteCfg() {
len += snprintf(content + len, maxLen - len, "}\n");
fwrite(content, 1, len, fp);
fsync(fileno(fp));
taosFsync(fileno(fp));
fclose(fp);
free(content);
terrno = 0;
......
......@@ -277,7 +277,7 @@ static int32_t dnodeWriteEps() {
len += snprintf(content + len, maxLen - len, "}\n");
fwrite(content, 1, len, fp);
fsync(fileno(fp));
taosFsync(fileno(fp));
fclose(fp);
free(content);
terrno = 0;
......
......@@ -286,7 +286,7 @@ static int32_t dnodeWriteMInfos() {
len += snprintf(content + len, maxLen - len, "}\n");
fwrite(content, 1, len, fp);
fsync(fileno(fp));
taosFsync(fileno(fp));
fclose(fp);
free(content);
terrno = 0;
......
......@@ -142,7 +142,7 @@ static void *shellCheckThreadFp(void *arg) {
taos_free_result(pSql);
}
fsync(fileno(fp));
taosFsync(fileno(fp));
fclose(fp);
return NULL;
......
......@@ -123,7 +123,7 @@ static void mnodePrintUserAuth() {
mnodeDecUserRef(pUser);
}
fsync(fileno(fp));
taosFsync(fileno(fp));
fclose(fp);
}
......
......@@ -58,7 +58,6 @@ extern "C" {
#include "osDef.h"
#include "osAtomic.h"
#include "osCommon.h"
#include "osDir.h"
#include "osFile.h"
#include "osLz4.h"
......@@ -67,6 +66,7 @@ extern "C" {
#include "osRand.h"
#include "osSemphone.h"
#include "osSignal.h"
#include "osSleep.h"
#include "osSocket.h"
#include "osString.h"
#include "osSysinfo.h"
......
......@@ -20,7 +20,252 @@
extern "C" {
#endif
#ifndef TAOS_OS_FUNC_ATOMIC
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define atomic_load_8(ptr) (*(char volatile*)(ptr))
#define atomic_load_16(ptr) (*(short volatile*)(ptr))
#define atomic_load_32(ptr) (*(long volatile*)(ptr))
#define atomic_load_64(ptr) (*(__int64 volatile*)(ptr))
#define atomic_load_ptr(ptr) (*(void* volatile*)(ptr))
#define atomic_store_8(ptr, val) ((*(char volatile*)(ptr)) = (char)(val))
#define atomic_store_16(ptr, val) ((*(short volatile*)(ptr)) = (short)(val))
#define atomic_store_32(ptr, val) ((*(long volatile*)(ptr)) = (long)(val))
#define atomic_store_64(ptr, val) ((*(__int64 volatile*)(ptr)) = (__int64)(val))
#define atomic_store_ptr(ptr, val) ((*(void* volatile*)(ptr)) = (void*)(val))
#define atomic_exchange_8(ptr, val) _InterlockedExchange8((char volatile*)(ptr), (char)(val))
#define atomic_exchange_16(ptr, val) _InterlockedExchange16((short volatile*)(ptr), (short)(val))
#define atomic_exchange_32(ptr, val) _InterlockedExchange((long volatile*)(ptr), (long)(val))
#define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64
#define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
#else
#define atomic_exchange_ptr(ptr, val) _InlineInterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
#endif
#ifdef _TD_GO_DLL_
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
#else
#define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval))
#endif
#define atomic_val_compare_exchange_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval))
#define atomic_val_compare_exchange_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval))
#define atomic_val_compare_exchange_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval))
#define atomic_val_compare_exchange_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval))
char interlocked_add_fetch_8(char volatile *ptr, char val);
short interlocked_add_fetch_16(short volatile *ptr, short val);
long interlocked_add_fetch_32(long volatile *ptr, long val);
__int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val);
char interlocked_and_fetch_8(char volatile* ptr, char val);
short interlocked_and_fetch_16(short volatile* ptr, short val);
long interlocked_and_fetch_32(long volatile* ptr, long val);
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val);
__int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val);
char interlocked_or_fetch_8(char volatile* ptr, char val);
short interlocked_or_fetch_16(short volatile* ptr, short val);
long interlocked_or_fetch_32(long volatile* ptr, long val);
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val);
char interlocked_xor_fetch_8(char volatile* ptr, char val);
short interlocked_xor_fetch_16(short volatile* ptr, short val);
long interlocked_xor_fetch_32(long volatile* ptr, long val);
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val);
__int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val);
#define atomic_add_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_add_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_add_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_add_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _TD_GO_DLL_
#define atomic_fetch_add_8 __sync_fetch_and_ad
#define atomic_fetch_add_16 __sync_fetch_and_add
#else
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
#endif
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_add_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val))
#define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_sub_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), -(char)(val))
#define atomic_sub_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), -(short)(val))
#define atomic_sub_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), -(long)(val))
#define atomic_sub_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), -(__int64)(val))
#define atomic_fetch_sub_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), -(char)(val))
#define atomic_fetch_sub_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), -(short)(val))
#define atomic_fetch_sub_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), -(long)(val))
#define atomic_fetch_sub_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), -(__int64)(val))
#define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val))
#define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val))
#define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val))
#define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64
#define atomic_add_fetch_ptr atomic_add_fetch_64
#define atomic_fetch_add_ptr atomic_fetch_add_64
#define atomic_sub_fetch_ptr atomic_sub_fetch_64
#define atomic_fetch_sub_ptr atomic_fetch_sub_64
#define atomic_and_fetch_ptr atomic_and_fetch_64
#define atomic_fetch_and_ptr atomic_fetch_and_64
#define atomic_or_fetch_ptr atomic_or_fetch_64
#define atomic_fetch_or_ptr atomic_fetch_or_64
#define atomic_xor_fetch_ptr atomic_xor_fetch_64
#define atomic_fetch_xor_ptr atomic_fetch_xor_64
#else
#define atomic_add_fetch_ptr atomic_add_fetch_32
#define atomic_fetch_add_ptr atomic_fetch_add_32
#define atomic_sub_fetch_ptr atomic_sub_fetch_32
#define atomic_fetch_sub_ptr atomic_fetch_sub_32
#define atomic_and_fetch_ptr atomic_and_fetch_32
#define atomic_fetch_and_ptr atomic_fetch_and_32
#define atomic_or_fetch_ptr atomic_or_fetch_32
#define atomic_fetch_or_ptr atomic_fetch_or_32
#define atomic_xor_fetch_ptr atomic_xor_fetch_32
#define atomic_fetch_xor_ptr atomic_fetch_xor_32
#endif
#elif defined(_TD_NINGSI_60)
/*
* type __sync_fetch_and_add (type *ptr, type value);
* type __sync_fetch_and_sub (type *ptr, type value);
* type __sync_fetch_and_or (type *ptr, type value);
* type __sync_fetch_and_and (type *ptr, type value);
* type __sync_fetch_and_xor (type *ptr, type value);
* type __sync_fetch_and_nand (type *ptr, type value);
* type __sync_add_and_fetch (type *ptr, type value);
* type __sync_sub_and_fetch (type *ptr, type value);
* type __sync_or_and_fetch (type *ptr, type value);
* type __sync_and_and_fetch (type *ptr, type value);
* type __sync_xor_and_fetch (type *ptr, type value);
* type __sync_nand_and_fetch (type *ptr, type value);
*
* bool __sync_bool_compare_and_swap (type*ptr, type oldval, type newval, ...)
* type __sync_val_compare_and_swap (type *ptr, type oldval, ?type newval, ...)
* */
#define atomic_load_8(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_16(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_32(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_64(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_ptr(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_store_8(ptr, val) (*(ptr)=(val))
#define atomic_store_16(ptr, val) (*(ptr)=(val))
#define atomic_store_32(ptr, val) (*(ptr)=(val))
#define atomic_store_64(ptr, val) (*(ptr)=(val))
#define atomic_store_ptr(ptr, val) (*(ptr)=(val))
int8_t atomic_exchange_8_impl(int8_t* ptr, int8_t val );
int16_t atomic_exchange_16_impl(int16_t* ptr, int16_t val );
int32_t atomic_exchange_32_impl(int32_t* ptr, int32_t val );
int64_t atomic_exchange_64_impl(int64_t* ptr, int64_t val );
void* atomic_exchange_ptr_impl( void **ptr, void *val );
#define atomic_exchange_8(ptr, val) atomic_exchange_8_impl((int8_t*)ptr, (int8_t)val)
#define atomic_exchange_16(ptr, val) atomic_exchange_16_impl((int16_t*)ptr, (int16_t)val)
#define atomic_exchange_32(ptr, val) atomic_exchange_32_impl((int32_t*)ptr, (int32_t)val)
#define atomic_exchange_64(ptr, val) atomic_exchange_64_impl((int64_t*)ptr, (int64_t)val)
#define atomic_exchange_ptr(ptr, val) atomic_exchange_ptr_impl((void **)ptr, (void*)val)
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
#define atomic_add_fetch_8(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_16(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_32(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_64(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_ptr(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_fetch_add_8(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_16(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_32(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_64(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_ptr(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_sub_fetch_8(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_16(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_32(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_64(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_ptr(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_fetch_sub_8(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_16(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_32(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_64(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_ptr(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_and_fetch_8(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_16(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_32(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_64(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_ptr(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_fetch_and_8(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_16(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_32(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_64(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_ptr(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_or_fetch_8(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_16(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_32(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_64(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_ptr(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_fetch_or_8(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_16(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_32(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_64(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_ptr(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_xor_fetch_8(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_16(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_32(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_64(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_ptr(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_fetch_xor_8(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_16(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_32(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_64(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_ptr(ptr, val) __sync_fetch_and_xor((ptr), (val))
#else
#define atomic_load_8(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
#define atomic_load_16(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
#define atomic_load_32(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
......
......@@ -71,24 +71,9 @@ extern "C" {
#include <fcntl.h>
#include <sys/utsname.h>
#include <math.h>
#define TAOS_OS_FUNC_FILE_SENDIFLE
#define TAOS_OS_FUNC_SEMPHONE
typedef struct tsem_s *tsem_t;
int tsem_init(tsem_t *sem, int pshared, unsigned int value);
int tsem_wait(tsem_t *sem);
int tsem_post(tsem_t *sem);
int tsem_destroy(tsem_t *sem);
#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
#define TAOS_OS_FUNC_STRING_STR2INT64
#define TAOS_OS_FUNC_SYSINFO
#define TAOS_OS_FUNC_TIMER
#define TAOS_OS_FUNC_SEMPHONE_PTHREAD
#include "osEok.h"
// specific
#define htobe64 htonll
typedef int(*__compar_fn_t)(const void *, const void *);
// for send function in tsocket.c
......@@ -106,19 +91,6 @@ typedef int(*__compar_fn_t)(const void *, const void *);
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
#endif
#define TAOS_OS_FUNC_PTHREAD_RWLOCK
int64_t tsosStr2int64(char *str);
#include "eok.h"
void taos_block_sigalrm(void);
#define TAOS_OS_DEF_EPOLL
#define TAOS_EPOLL_WAIT_TIME 500
typedef int32_t SOCKET;
typedef SOCKET EpollFd;
#define EpollClose(pollFd) epoll_close(pollFd)
#ifdef __cplusplus
}
......
......@@ -26,11 +26,6 @@ extern "C" {
#endif
#endif
#define FD_VALID(x) ((x) > STDERR_FILENO)
#define FD_INITIALIZER ((int32_t)-1)
// #define WCHAR wchar_t
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
......@@ -113,6 +108,12 @@ extern "C" {
#define threadlocal __declspec( thread )
#endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define PRIzu "ld"
#else
#define PRIzu "zu"
#endif
#ifdef __cplusplus
}
#endif
......
......@@ -20,13 +20,10 @@
extern "C" {
#endif
#include <sys/types.h>
// TAOS_OS_FUNC_DIR
void taosRemoveDir(char *rootDir);
int taosMkDir(const char *pathname, mode_t mode);
int32_t taosMkDir(const char *pathname, mode_t mode);
void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays);
int32_t taosRename(char* oldName, char *newName);
int32_t taosRename(char *oldName, char *newName);
int32_t taosCompressFile(char *srcFileName, char *destFileName);
#ifdef __cplusplus
......
......@@ -22,48 +22,37 @@ extern "C" {
#include "osSocket.h"
int64_t taosReadImp(int32_t fd, void *buf, int64_t count);
int64_t taosWriteImp(int32_t fd, void *buf, int64_t count);
int64_t taosLSeekImp(int32_t fd, int64_t offset, int32_t whence);
int32_t taosRenameFile(char *fullPath, char *suffix, char delimiter, char **dstPath);
int64_t taosCopy(char *from, char *to);
#define taosRead(fd, buf, count) taosReadImp(fd, buf, count)
#define taosWrite(fd, buf, count) taosWriteImp(fd, buf, count)
#define taosLSeek(fd, offset, whence) taosLSeekImp(fd, offset, whence)
#define taosClose(fd) \
{ \
if (FD_VALID(fd)) { \
close(fd); \
fd = FD_INITIALIZER; \
} \
}
#define FD_VALID(x) ((x) > STDERR_FILENO)
#define FD_INITIALIZER ((int32_t)-1)
// TAOS_OS_FUNC_FILE_SENDIFLE
int64_t taosSendFile(SOCKET dfd, int32_t sfd, int64_t *offset, int64_t size);
int64_t taosFSendFile(FILE *outfile, FILE *infile, int64_t *offset, int64_t size);
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
#ifdef TAOS_RANDOM_FILE_FAIL
void taosSetRandomFileFailFactor(int32_t factor);
void taosSetRandomFileFailOutput(const char *path);
#ifdef TAOS_RANDOM_FILE_FAIL_TEST
int64_t taosReadFileRandomFail(int32_t fd, void *buf, int32_t count, const char *file, uint32_t line);
int64_t taosWriteFileRandomFail(int32_t fd, void *buf, int32_t count, const char *file, uint32_t line);
int64_t taosLSeekRandomFail(int32_t fd, int64_t offset, int32_t whence, const char *file, uint32_t line);
#undef taosRead
#undef taosWrite
#undef taosLSeek
#define taosRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__)
#define taosWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__)
#define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__)
#endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
typedef int32_t FileFd;
typedef SOCKET SocketFd;
#else
typedef int32_t FileFd;
typedef int32_t SocketFd;
#endif
// TAOS_OS_FUNC_FILE_GETTMPFILEPATH
int64_t taosRead(FileFd fd, void *buf, int64_t count);
int64_t taosWrite(FileFd fd, void *buf, int64_t count);
int64_t taosLSeek(FileFd fd, int64_t offset, int32_t whence);
int32_t taosFtruncate(FileFd fd, int64_t length);
int32_t taosFsync(FileFd fd);
int32_t taosRename(char* oldName, char *newName);
int64_t taosCopy(char *from, char *to);
int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t size);
int64_t taosFSendFile(FILE *outfile, FILE *infile, int64_t *offset, int64_t size);
void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath);
void taosClose(FileFd fd);
// TAOS_OS_FUNC_FILE_FTRUNCATE
int32_t taosFtruncate(int32_t fd, int64_t length);
#ifdef __cplusplus
}
#endif
......
......@@ -79,12 +79,6 @@ extern "C" {
#include <math.h>
#include <poll.h>
#define TAOS_OS_FUNC_LZ4
#define BUILDIN_CLZL(val) __builtin_clzll(val)
#define BUILDIN_CTZL(val) __builtin_ctzll(val)
#define BUILDIN_CLZ(val) __builtin_clz(val)
#define BUILDIN_CTZ(val) __builtin_ctz(val)
#ifdef __cplusplus
}
#endif
......
......@@ -20,7 +20,22 @@
extern "C" {
#endif
#ifndef TAOS_OS_FUNC_LZ4
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
int32_t BUILDIN_CLZL(uint64_t val);
int32_t BUILDIN_CLZ(uint32_t val);
int32_t BUILDIN_CTZL(uint64_t val);
int32_t BUILDIN_CTZ(uint32_t val);
#elif defined (_TD_LINUX_32)
#define BUILDIN_CLZL(val) __builtin_clzll(val)
#define BUILDIN_CTZL(val) __builtin_ctzll(val)
#define BUILDIN_CLZ(val) __builtin_clz(val)
#define BUILDIN_CTZ(val) __builtin_ctz(val)
#elif defined (_TD_ARM_32)
#define BUILDIN_CLZL(val) __builtin_clzll(val)
#define BUILDIN_CTZL(val) __builtin_ctzll(val)
#define BUILDIN_CLZ(val) __builtin_clz(val)
#define BUILDIN_CTZ(val) __builtin_ctz(val)
#else
#define BUILDIN_CLZL(val) __builtin_clzl(val)
#define BUILDIN_CTZL(val) __builtin_ctzl(val)
#define BUILDIN_CLZ(val) __builtin_clz(val)
......
......@@ -23,7 +23,19 @@ extern "C" {
#define POW2(x) ((x) * (x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#ifndef TAOS_OS_FUNC_MATH
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define SWAP(a, b, c) \
do { \
c __tmp = (c)(a); \
(a) = (c)(b); \
(b) = __tmp; \
} while (0)
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#else
#define SWAP(a, b, c) \
do { \
typeof(a) __tmp = (a); \
......
......@@ -43,9 +43,6 @@ void taosTMemset(void *ptr, int c);
#define tmalloc(size) malloc(size)
#define tcalloc(num, size) calloc(num, size)
#define trealloc(ptr, size) realloc(ptr, size)
#define tstrdup(str) taosStrdupImp(str)
#define tstrndup(str, size) taosStrndupImp(str, size)
#define tgetline(lineptr, n, stream) taosGetlineImp(lineptr, n, stream)
#define tfree(x) \
do { \
if (x) { \
......@@ -71,13 +68,6 @@ void taosTMemset(void *ptr, int c);
#define tcalloc(num, size) taosCallocMem(num, size, __FILE__, __LINE__)
#define trealloc(ptr, size) taosReallocMem(ptr, size, __FILE__, __LINE__)
#define tfree(ptr) taosFreeMem(ptr, __FILE__, __LINE__)
// #undef tstrdup
// #undef tstrndup
// #undef tgetline
// #define taosStrdup(str) taos_strdup(str, __FILE__, __LINE__)
// #define taosStrndup(str, size) taos_strndup(str, size, __FILE__, __LINE__)
// #define tgetline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__)
#endif
#endif
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_OS_NINGSI_H
#define TDENGINE_OS_NINGSI_H
#ifdef __cplusplus
extern "C" {
#endif
#define TAOS_OS_FUNC_ATOMIC
/*
* type __sync_fetch_and_add (type *ptr, type value);
* type __sync_fetch_and_sub (type *ptr, type value);
* type __sync_fetch_and_or (type *ptr, type value);
* type __sync_fetch_and_and (type *ptr, type value);
* type __sync_fetch_and_xor (type *ptr, type value);
* type __sync_fetch_and_nand (type *ptr, type value);
* type __sync_add_and_fetch (type *ptr, type value);
* type __sync_sub_and_fetch (type *ptr, type value);
* type __sync_or_and_fetch (type *ptr, type value);
* type __sync_and_and_fetch (type *ptr, type value);
* type __sync_xor_and_fetch (type *ptr, type value);
* type __sync_nand_and_fetch (type *ptr, type value);
*
* bool __sync_bool_compare_and_swap (type*ptr, type oldval, type newval, ...)
* type __sync_val_compare_and_swap (type *ptr, type oldval, ?type newval, ...)
* */
#define atomic_load_8(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_16(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_32(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_64(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_ptr(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_store_8(ptr, val) (*(ptr)=(val))
#define atomic_store_16(ptr, val) (*(ptr)=(val))
#define atomic_store_32(ptr, val) (*(ptr)=(val))
#define atomic_store_64(ptr, val) (*(ptr)=(val))
#define atomic_store_ptr(ptr, val) (*(ptr)=(val))
int8_t atomic_exchange_8_impl(int8_t* ptr, int8_t val );
int16_t atomic_exchange_16_impl(int16_t* ptr, int16_t val );
int32_t atomic_exchange_32_impl(int32_t* ptr, int32_t val );
int64_t atomic_exchange_64_impl(int64_t* ptr, int64_t val );
void* atomic_exchange_ptr_impl( void **ptr, void *val );
#define atomic_exchange_8(ptr, val) atomic_exchange_8_impl((int8_t*)ptr, (int8_t)val)
#define atomic_exchange_16(ptr, val) atomic_exchange_16_impl((int16_t*)ptr, (int16_t)val)
#define atomic_exchange_32(ptr, val) atomic_exchange_32_impl((int32_t*)ptr, (int32_t)val)
#define atomic_exchange_64(ptr, val) atomic_exchange_64_impl((int64_t*)ptr, (int64_t)val)
#define atomic_exchange_ptr(ptr, val) atomic_exchange_ptr_impl((void **)ptr, (void*)val)
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
#define atomic_add_fetch_8(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_16(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_32(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_64(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_ptr(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_fetch_add_8(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_16(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_32(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_64(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_ptr(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_sub_fetch_8(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_16(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_32(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_64(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_ptr(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_fetch_sub_8(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_16(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_32(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_64(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_ptr(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_and_fetch_8(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_16(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_32(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_64(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_ptr(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_fetch_and_8(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_16(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_32(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_64(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_ptr(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_or_fetch_8(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_16(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_32(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_64(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_ptr(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_fetch_or_8(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_16(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_32(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_64(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_ptr(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_xor_fetch_8(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_16(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_32(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_64(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_ptr(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_fetch_xor_8(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_16(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_32(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_64(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_ptr(ptr, val) __sync_fetch_and_xor((ptr), (val))
#ifdef __cplusplus
}
#endif
#endif
......@@ -20,7 +20,6 @@
extern "C" {
#endif
// TAOS_OS_FUNC_RAND
uint32_t taosRand(void);
void taosRandStr(char* str, int32_t size);
uint32_t taosSafeRand(void);
......
......@@ -20,7 +20,13 @@
extern "C" {
#endif
#ifndef TAOS_OS_FUNC_SEMPHONE
#if defined (_TD_DARWIN_64)
typedef struct tsem_s *tsem_t;
int tsem_init(tsem_t *sem, int pshared, unsigned int value);
int tsem_wait(tsem_t *sem);
int tsem_post(tsem_t *sem);
int tsem_destroy(tsem_t *sem);
#else
#define tsem_t sem_t
#define tsem_init sem_init
int tsem_wait(tsem_t* sem);
......@@ -28,7 +34,7 @@ extern "C" {
#define tsem_destroy sem_destroy
#endif
#ifdef TAOS_OS_FUNC_PTHREAD_RWLOCK
#if defined (_TD_DARWIN_64)
#define pthread_rwlock_t pthread_mutex_t
#define pthread_rwlock_init(lock, NULL) pthread_mutex_init(lock, NULL)
#define pthread_rwlock_destroy(lock) pthread_mutex_destroy(lock)
......@@ -43,7 +49,6 @@ extern "C" {
#define pthread_spin_unlock(lock) pthread_mutex_unlock(lock)
#endif
// TAOS_OS_FUNC_SEMPHONE_PTHREAD
bool taosCheckPthreadValid(pthread_t thread);
int64_t taosGetSelfPthreadId();
int64_t taosGetPthreadId(pthread_t thread);
......
......@@ -20,8 +20,6 @@
extern "C" {
#endif
#include "os.h"
#include "taosdef.h"
#include <signal.h>
#ifndef SIGALRM
......@@ -57,4 +55,4 @@ void taosDflSignal(int32_t signum);
}
#endif
#endif // TDENGINE_TTIME_H
#endif // TDENGINE_OS_SIGNAL_H
......@@ -13,16 +13,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_OS_COMMON_H
#define TDENGINE_OS_COMMON_H
#ifndef TDENGINE_OS_SLEEP_H
#define TDENGINE_OS_SLEEP_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef TAOS_OS_DEF_ZU
#define PRIzu "zu"
#endif
void taosMsleep(int32_t ms);
#ifdef __cplusplus
}
......
......@@ -20,7 +20,14 @@
extern "C" {
#endif
#ifndef TAOS_OS_FUNC_SOCKET_OP
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define taosSend(sockfd, buf, len, flags) send((SOCKET)sockfd, buf, len, flags)
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto((SOCKET)sockfd, buf, len, flags, dest_addr, addrlen)
#define taosWriteSocket(fd, buf, len) send((SOCKET)fd, buf, len, 0)
#define taosReadSocket(fd, buf, len) recv((SOCKET)fd, buf, len, 0)
#define taosCloseSocketNoCheck(fd) closesocket((SOCKET)fd)
#define taosCloseSocket(fd) closesocket((SOCKET)fd)
#else
#define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen)
#define taosReadSocket(fd, buf, len) read(fd, buf, len)
......@@ -35,7 +42,21 @@ extern "C" {
}
#endif
#ifndef TAOS_OS_DEF_EPOLL
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define TAOS_EPOLL_WAIT_TIME 100
typedef SOCKET eventfd_t;
#define eventfd(a, b) -1
typedef SOCKET EpollFd;
#define EpollClose(pollFd) epoll_close(pollFd)
#ifndef EPOLLWAKEUP
#define EPOLLWAKEUP (1u << 29)
#endif
#elif defined(_TD_DARWIN_64)
#define TAOS_EPOLL_WAIT_TIME 500
typedef int32_t SOCKET;
typedef SOCKET EpollFd;
#define EpollClose(pollFd) epoll_close(pollFd)
#else
#define TAOS_EPOLL_WAIT_TIME 500
typedef int32_t SOCKET;
typedef SOCKET EpollFd;
......@@ -59,21 +80,25 @@ extern "C" {
#endif
#endif
// TAOS_OS_FUNC_SOCKET
int32_t taosSetNonblocking(SOCKET sock, int32_t on);
void taosIgnSIGPIPE();
void taosBlockSIGPIPE();
void taosSetMaskSIGPIPE();
// TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t optlen);
int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t* optlen);
// TAOS_OS_FUNC_SOCKET_INET
uint32_t taosInetAddr(char *ipAddr);
const char *taosInetNtoa(struct in_addr ipInt);
#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
#define htobe64 htonll
#if defined(_TD_GO_DLL_)
uint64_t htonll(uint64_t val);
#endif
#elif defined(_TD_DARWIN_64)
#define htobe64 htonll
#endif
#ifdef __cplusplus
}
#endif
......
......@@ -20,18 +20,15 @@
extern "C" {
#endif
#ifndef TAOS_OS_FUNC_STRING_STRDUP
#define taosStrdupImp(str) strdup(str)
#define taosStrndupImp(str, size) strndup(str, size)
#endif
#ifndef TAOS_OS_FUNC_STRING_GETLINE
#define taosGetlineImp(lineptr, n, stream) getline(lineptr, n , stream)
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define tstrdup(str) _strdup(str)
#define tstrndup(str, size) _strndup(str, size)
int32_t tgetline(char **lineptr, size_t *n, FILE *stream);
int32_t twcslen(const wchar_t *wcs);
#else
int taosGetlineImp(char **lineptr, size_t *n, FILE *stream);
#endif
#ifndef TAOS_OS_FUNC_STRING_WCHAR
#define tstrdup(str) strdup(str)
#define tstrndup(str, size) strndup(str, size)
#define tgetline(lineptr, n, stream) getline(lineptr, n, stream)
#define twcslen wcslen
#endif
......@@ -41,14 +38,12 @@ extern "C" {
(dst)[(size)-1] = 0; \
} while (0)
#ifndef TAOS_OS_FUNC_STRING_STR2INT64
int64_t tsosStr2int64(char *str);
#endif
int64_t taosStr2int64(char *str);
// USE_LIBICONV
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int *len);
int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes);
bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t *len);
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes);
bool taosValidateEncodec(const char *encodec);
char * taosCharsetReplace(char *charsetstr);
......
......@@ -20,7 +20,6 @@
extern "C" {
#endif
// TAOS_OS_FUNC_SYSINFO
typedef struct {
int64_t tsize;
int64_t used;
......@@ -32,16 +31,15 @@ void taosGetSystemInfo();
bool taosGetProcIO(float *readKB, float *writeKB);
bool taosGetBandSpeed(float *bandSpeedKb);
void taosGetDisk();
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) ;
bool taosGetProcMemory(float *memoryUsedMB) ;
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage);
bool taosGetProcMemory(float *memoryUsedMB);
bool taosGetSysMemory(float *memoryUsedMB);
void taosPrintOsInfo();
int taosSystem(const char * cmd) ;
int taosSystem(const char *cmd);
void taosKillSystem();
bool taosGetSystemUid(char *uid);
char *taosGetCmdlineByPID(int pid);
char * taosGetCmdlineByPID(int pid);
// TAOS_OS_FUNC_SYSINFO_CORE
void taosSetCoreDump();
#ifdef __cplusplus
......
......@@ -23,9 +23,16 @@ extern "C" {
#include "os.h"
#include "taosdef.h"
#ifndef TAOS_OS_FUNC_TIME_DEF
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#ifdef _TD_GO_DLL_
#define MILLISECOND_PER_SECOND (1000LL)
#else
#define MILLISECOND_PER_SECOND (1000i64)
#endif
#else
#define MILLISECOND_PER_SECOND ((int64_t)1000L)
#endif
#define MILLISECOND_PER_MINUTE (MILLISECOND_PER_SECOND * 60)
#define MILLISECOND_PER_HOUR (MILLISECOND_PER_MINUTE * 60)
#define MILLISECOND_PER_DAY (MILLISECOND_PER_HOUR * 24)
......
......@@ -20,8 +20,6 @@
extern "C" {
#endif
// TAOS_OS_FUNC_TIMER
void taosMsleep(int mseconds);
int taosInitTimer(void (*callback)(int), int ms);
void taosUninitTimer();
......
......@@ -55,87 +55,9 @@
extern "C" {
#endif
#define TAOS_OS_FUNC_LZ4
int32_t BUILDIN_CLZL(uint64_t val);
int32_t BUILDIN_CLZ(uint32_t val);
int32_t BUILDIN_CTZL(uint64_t val);
int32_t BUILDIN_CTZ(uint32_t val);
#define TAOS_OS_FUNC_FILE
#define TAOS_OS_FUNC_FILE_ISREG
#define TAOS_OS_FUNC_FILE_ISDIR
#define TAOS_OS_FUNC_FILE_ISLNK
#define TAOS_OS_FUNC_FILE_SENDIFLE
#define TAOS_OS_FUNC_FILE_GETTMPFILEPATH
#define TAOS_OS_FUNC_FILE_FTRUNCATE
#define TAOS_OS_FUNC_DIR
#define TAOS_OS_FUNC_MATH
#define SWAP(a, b, c) \
do { \
c __tmp = (c)(a); \
(a) = (c)(b); \
(b) = __tmp; \
} while (0)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define TAOS_OS_FUNC_SEMPHONE_PTHREAD
#define TAOS_OS_FUNC_SOCKET
#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
#define TAOS_OS_FUNC_SOCKET_OP
#define taosSend(sockfd, buf, len, flags) send((SOCKET)sockfd, buf, len, flags)
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto((SOCKET)sockfd, buf, len, flags, dest_addr, addrlen)
#define taosWriteSocket(fd, buf, len) send((SOCKET)fd, buf, len, 0)
#define taosReadSocket(fd, buf, len) recv((SOCKET)fd, buf, len, 0)
#define taosCloseSocketNoCheck(fd) closesocket((SOCKET)fd)
#define taosCloseSocket(fd) closesocket((SOCKET)fd)
typedef SOCKET eventfd_t;
#define eventfd(a, b) -1
#define TAOS_OS_DEF_EPOLL
#define TAOS_EPOLL_WAIT_TIME 100
typedef SOCKET EpollFd;
#define EpollClose(pollFd) epoll_close(pollFd)
#ifndef EPOLLWAKEUP
#define EPOLLWAKEUP (1u << 29)
#endif
#define TAOS_OS_DEF_ZU
#define PRIzu "ld"
#define TAOS_OS_FUNC_STRING_WCHAR
int twcslen(const wchar_t *wcs);
#define TAOS_OS_FUNC_STRING_GETLINE
#define TAOS_OS_FUNC_STRING_STR2INT64
#ifdef _TD_GO_DLL_
int64_t tsosStr2int64(char *str);
uint64_t htonll(uint64_t val);
#else
#define tsosStr2int64 _atoi64
#endif
#define TAOS_OS_FUNC_STRING_STRDUP
#define taosStrdupImp(str) _strdup(str)
#define taosStrndupImp(str, size) _strndup(str, size)
char *stpcpy (char *dest, const char *src);
char *stpncpy (char *dest, const char *src, size_t n);
#define TAOS_OS_FUNC_SYSINFO
#define TAOS_OS_FUNC_TIME_DEF
#ifdef _TD_GO_DLL_
#define MILLISECOND_PER_SECOND (1000LL)
#else
#define MILLISECOND_PER_SECOND (1000i64)
#endif
#define TAOS_OS_FUNC_TIMER_SLEEP
#define TAOS_OS_FUNC_TIMER
// specific
typedef int (*__compar_fn_t)(const void *, const void *);
#define ssize_t int
......@@ -147,14 +69,12 @@ typedef int (*__compar_fn_t)(const void *, const void *);
#define snprintf _snprintf
#define in_addr_t unsigned long
#define socklen_t int
#define htobe64 htonll
struct tm *localtime_r(const time_t *timep, struct tm *result);
char * strptime(const char *buf, const char *fmt, struct tm *tm);
char * strsep(char **stringp, const char *delim);
char * getpass(const char *prefix);
int flock(int fd, int option);
int fsync(int filedes);
char * strndup(const char *s, size_t n);
int gettimeofday(struct timeval *ptv, void *pTimeZone);
......@@ -175,12 +95,6 @@ int gettimeofday(struct timeval *ptv, void *pTimeZone);
#define TCP_KEEPINTVL 0x1234
#endif
#ifdef _MSC_VER
//#if _MSC_VER >= 1900
#define TAOS_OS_FUNC_SOCKET_INET
//#endif
#endif
#define SHUT_RDWR SD_BOTH
#define SHUT_RD SD_RECEIVE
#define SHUT_WR SD_SEND
......@@ -193,8 +107,6 @@ int gettimeofday(struct timeval *ptv, void *pTimeZone);
#define PATH_MAX 256
#endif
#define TAOS_OS_FUNC_SIGNAL
typedef struct {
int we_wordc;
char *we_wordv[1];
......@@ -210,142 +122,6 @@ void wordfree(wordexp_t *pwordexp);
#define LOG_INFO 1
void syslog(int unused, const char *format, ...);
#define TAOS_OS_FUNC_ATOMIC
#define atomic_load_8(ptr) (*(char volatile*)(ptr))
#define atomic_load_16(ptr) (*(short volatile*)(ptr))
#define atomic_load_32(ptr) (*(long volatile*)(ptr))
#define atomic_load_64(ptr) (*(__int64 volatile*)(ptr))
#define atomic_load_ptr(ptr) (*(void* volatile*)(ptr))
#define atomic_store_8(ptr, val) ((*(char volatile*)(ptr)) = (char)(val))
#define atomic_store_16(ptr, val) ((*(short volatile*)(ptr)) = (short)(val))
#define atomic_store_32(ptr, val) ((*(long volatile*)(ptr)) = (long)(val))
#define atomic_store_64(ptr, val) ((*(__int64 volatile*)(ptr)) = (__int64)(val))
#define atomic_store_ptr(ptr, val) ((*(void* volatile*)(ptr)) = (void*)(val))
#define atomic_exchange_8(ptr, val) _InterlockedExchange8((char volatile*)(ptr), (char)(val))
#define atomic_exchange_16(ptr, val) _InterlockedExchange16((short volatile*)(ptr), (short)(val))
#define atomic_exchange_32(ptr, val) _InterlockedExchange((long volatile*)(ptr), (long)(val))
#define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64
#define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
#else
#define atomic_exchange_ptr(ptr, val) _InlineInterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
#endif
#ifdef _TD_GO_DLL_
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
#else
#define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval))
#endif
#define atomic_val_compare_exchange_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval))
#define atomic_val_compare_exchange_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval))
#define atomic_val_compare_exchange_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval))
#define atomic_val_compare_exchange_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval))
char interlocked_add_fetch_8(char volatile *ptr, char val);
short interlocked_add_fetch_16(short volatile *ptr, short val);
long interlocked_add_fetch_32(long volatile *ptr, long val);
__int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val);
char interlocked_and_fetch_8(char volatile* ptr, char val);
short interlocked_and_fetch_16(short volatile* ptr, short val);
long interlocked_and_fetch_32(long volatile* ptr, long val);
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val);
__int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val);
char interlocked_or_fetch_8(char volatile* ptr, char val);
short interlocked_or_fetch_16(short volatile* ptr, short val);
long interlocked_or_fetch_32(long volatile* ptr, long val);
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val);
char interlocked_xor_fetch_8(char volatile* ptr, char val);
short interlocked_xor_fetch_16(short volatile* ptr, short val);
long interlocked_xor_fetch_32(long volatile* ptr, long val);
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val);
__int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val);
#define atomic_add_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_add_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_add_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_add_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _TD_GO_DLL_
#define atomic_fetch_add_8 __sync_fetch_and_ad
#define atomic_fetch_add_16 __sync_fetch_and_add
#else
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
#endif
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_add_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val))
#define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_sub_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), -(char)(val))
#define atomic_sub_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), -(short)(val))
#define atomic_sub_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), -(long)(val))
#define atomic_sub_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), -(__int64)(val))
#define atomic_fetch_sub_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), -(char)(val))
#define atomic_fetch_sub_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), -(short)(val))
#define atomic_fetch_sub_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), -(long)(val))
#define atomic_fetch_sub_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), -(__int64)(val))
#define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val))
#define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val))
#define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val))
#define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64
#define atomic_add_fetch_ptr atomic_add_fetch_64
#define atomic_fetch_add_ptr atomic_fetch_add_64
#define atomic_sub_fetch_ptr atomic_sub_fetch_64
#define atomic_fetch_sub_ptr atomic_fetch_sub_64
#define atomic_and_fetch_ptr atomic_and_fetch_64
#define atomic_fetch_and_ptr atomic_fetch_and_64
#define atomic_or_fetch_ptr atomic_or_fetch_64
#define atomic_fetch_or_ptr atomic_fetch_or_64
#define atomic_xor_fetch_ptr atomic_xor_fetch_64
#define atomic_fetch_xor_ptr atomic_fetch_xor_64
#else
#define atomic_add_fetch_ptr atomic_add_fetch_32
#define atomic_fetch_add_ptr atomic_fetch_add_32
#define atomic_sub_fetch_ptr atomic_sub_fetch_32
#define atomic_fetch_sub_ptr atomic_fetch_sub_32
#define atomic_and_fetch_ptr atomic_and_fetch_32
#define atomic_fetch_and_ptr atomic_fetch_and_32
#define atomic_or_fetch_ptr atomic_or_fetch_32
#define atomic_fetch_or_ptr atomic_fetch_or_32
#define atomic_xor_fetch_ptr atomic_xor_fetch_32
#define atomic_fetch_xor_ptr atomic_fetch_xor_32
#endif
#ifdef __cplusplus
}
#endif
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "tulog.h"
int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t count) {
int r = 0;
if (offset) {
r = fseek(in_file, *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 = fread(buf, 1, n, in_file);
if (m<n) {
int e = ferror(in_file);
if (e) return -1;
}
if (m==0) break;
if (m!=fwrite(buf, 1, m, out_file)) {
return -1;
}
len -= m;
}
return count - len;
}
int64_t taosSendFile(SOCKET dfd, int32_t 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;
}
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
int64_t tsosStr2int64(char *str) {
char *endptr = NULL;
return strtoll(str, &endptr, 10);
}
......@@ -18,9 +18,9 @@
// https://stackoverflow.com/questions/4393197/erlangs-let-it-crash-philosophy-applicable-elsewhere
// experimentally, we follow log-and-crash here
#include "eok.h"
#define _DEFAULT_SOURCE
#include "os.h"
#include "osEok.h"
#include <sys/event.h>
......@@ -415,8 +415,6 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) {
static struct timespec do_timespec_diff(struct timespec *from, struct timespec *to);
int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) {
taos_block_sigalrm();
int e = 0;
if (!events) {
errno = EINVAL;
......
......@@ -20,7 +20,6 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include <libproc.h>
// #define SEM_USE_PTHREAD
......
......@@ -22,7 +22,6 @@
#include <errno.h>
#include <libproc.h>
static void taosGetSystemTimezone() {
SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone");
if (cfg_timezone == NULL) return;
......
......@@ -51,22 +51,6 @@ int taosMkDir(const char *path, mode_t mode) {
return code;
}
#ifndef TAOS_OS_FUNC_DIR
int32_t taosRename(char* oldName, char *newName) {
int32_t code = rename(oldName, newName);
if (code < 0) {
uError("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno));
} else {
uTrace("successfully to rename file %s to %s", oldName, newName);
}
return code;
}
#endif
void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays) {
DIR *dir = opendir(rootDir);
if (dir == NULL) return;
......
......@@ -16,65 +16,68 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "tglobal.h"
#include "tulog.h"
#ifndef TAOS_OS_FUNC_FILE_GETTMPFILEPATH
void taosClose(FileFd fd) {
close(fd);
fd = FD_INITIALIZER;
}
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) {
const char *tdengineTmpFileNamePrefix = "tdengine-";
char tmpPath[PATH_MAX];
int32_t len = strlen(tsTempDir);
int32_t len = (int32_t)strlen(tsTempDir);
memcpy(tmpPath, tsTempDir, len);
static uint64_t seqId = 0;
if (tmpPath[len - 1] != '/') {
tmpPath[len++] = '/';
if (tmpPath[len - 1] != '/' && tmpPath[len - 1] != '\\') {
tmpPath[len++] = '\\';
}
strcpy(tmpPath + len, tdengineTmpFileNamePrefix);
strcat(tmpPath, tdengineTmpFileNamePrefix);
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
strcat(tmpPath, fileNamePrefix);
strcat(tmpPath, "-%d-%s");
}
char rand[32] = {0};
sprintf(rand, "%"PRIu64, atomic_add_fetch_64(&seqId, 1));
char rand[8] = {0};
taosRandStr(rand, tListLen(rand) - 1);
snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand);
}
#endif
int32_t taosRenameFile(char *fullPath, char *suffix, char delimiter, char **dstPath) {
int32_t ts = taosGetTimestampSec();
#else
char fname[PATH_MAX] = {0}; // max file name length must be less than 255
void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) {
const char *tdengineTmpFileNamePrefix = "tdengine-";
char *delimiterPos = strrchr(fullPath, delimiter);
if (delimiterPos == NULL) return -1;
char tmpPath[PATH_MAX];
int32_t len = strlen(tsTempDir);
memcpy(tmpPath, tsTempDir, len);
static uint64_t seqId = 0;
int32_t fileNameLen = 0;
if (suffix) {
fileNameLen = snprintf(fname, PATH_MAX, "%s.%d.%s", delimiterPos + 1, ts, suffix);
} else {
fileNameLen = snprintf(fname, PATH_MAX, "%s.%d", delimiterPos + 1, ts);
if (tmpPath[len - 1] != '/') {
tmpPath[len++] = '/';
}
int32_t len = (int32_t)((delimiterPos - fullPath) + fileNameLen + 1);
if (*dstPath == NULL) {
*dstPath = calloc(1, len + 1);
if (*dstPath == NULL) return -1;
strcpy(tmpPath + len, tdengineTmpFileNamePrefix);
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
strcat(tmpPath, fileNamePrefix);
strcat(tmpPath, "-%d-%s");
}
strncpy(*dstPath, fullPath, (size_t)(delimiterPos - fullPath + 1));
strncat(*dstPath, fname, (size_t)fileNameLen);
(*dstPath)[len] = 0;
char rand[32] = {0};
sprintf(rand, "%" PRIu64, atomic_add_fetch_64(&seqId, 1));
return rename(fullPath, *dstPath);
snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand);
}
int64_t taosReadImp(int32_t fd, void *buf, int64_t count) {
#endif
int64_t taosRead(FileFd fd, void *buf, int64_t count) {
int64_t leftbytes = count;
int64_t readbytes;
char * tbuf = (char *)buf;
......@@ -98,7 +101,7 @@ int64_t taosReadImp(int32_t fd, void *buf, int64_t count) {
return count;
}
int64_t taosWriteImp(int32_t fd, void *buf, int64_t n) {
int64_t taosWrite(FileFd fd, void *buf, int64_t n) {
int64_t nleft = n;
int64_t nwritten = 0;
char * tbuf = (char *)buf;
......@@ -118,9 +121,7 @@ int64_t taosWriteImp(int32_t fd, void *buf, int64_t n) {
return n;
}
int64_t taosLSeekImp(int32_t fd, int64_t offset, int32_t whence) {
return (int64_t)lseek(fd, (long)offset, whence);
}
int64_t taosLSeek(FileFd fd, int64_t offset, int32_t whence) { return (int64_t)lseek(fd, (long)offset, whence); }
int64_t taosCopy(char *from, char *to) {
char buffer[4096];
......@@ -145,22 +146,139 @@ int64_t taosCopy(char *from, char *to) {
if (bytes < sizeof(buffer)) break;
}
fsync(fidto);
taosFsync(fidto);
close(fidfrom);
close(fidto);
taosClose(fidfrom);
taosClose(fidto);
return size;
_err:
if (fidfrom >= 0) close(fidfrom);
if (fidto >= 0) close(fidto);
if (fidfrom >= 0) taosClose(fidfrom);
if (fidto >= 0) taosClose(fidto);
remove(to);
return -1;
}
#ifndef TAOS_OS_FUNC_FILE_SENDIFLE
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define _SEND_FILE_STEP_ 1000
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;
}
}
return writeLen;
}
int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t count) {
if (offset != NULL) lseek(sfd, (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_) {
int32_t rlen = (int32_t)read(sfd, buffer, _SEND_FILE_STEP_);
if (rlen <= 0) {
return writeLen;
} else if (rlen < _SEND_FILE_STEP_) {
taosWriteSocket(dfd, buffer, rlen);
return (int64_t)(writeLen + rlen);
} else {
taosWriteSocket(dfd, buffer, _SEND_FILE_STEP_);
writeLen += _SEND_FILE_STEP_;
}
}
int64_t remain = count - writeLen;
if (remain > 0) {
int32_t rlen = read(sfd, buffer, (int32_t)remain);
if (rlen <= 0) {
return writeLen;
} else {
taosWriteSocket(sfd, buffer, (int32_t)remain);
writeLen += remain;
}
}
return writeLen;
}
#elif defined(_TD_DARWIN_64)
int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t count) {
int r = 0;
if (offset) {
r = fseek(in_file, *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 = fread(buf, 1, n, in_file);
if (m < n) {
int e = ferror(in_file);
if (e) return -1;
}
if (m == 0) break;
if (m != fwrite(buf, 1, m, out_file)) {
return -1;
}
len -= m;
}
return count - 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;
}
int64_t taosSendFile(SOCKET dfd, int32_t sfd, int64_t *offset, int64_t size) {
#else
int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t size) {
int64_t leftbytes = size;
int64_t sentbytes;
......@@ -188,10 +306,96 @@ int64_t taosFSendFile(FILE *outfile, FILE *infile, int64_t *offset, int64_t size
#endif
#ifndef TAOS_OS_FUNC_FILE_FTRUNCATE
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
int32_t taosFtruncate(int32_t fd, int64_t l_size) {
if (fd < 0) {
errno = EBADF;
uError("%s\n", "fd arg was negative");
return -1;
}
HANDLE h = (HANDLE)_get_osfhandle(fd);
LARGE_INTEGER li_0;
li_0.QuadPart = (int64_t)0;
BOOL cur = SetFilePointerEx(h, li_0, NULL, FILE_CURRENT);
if (!cur) {
uError("SetFilePointerEx Error getting current position in file.\n");
return -1;
}
LARGE_INTEGER li_size;
li_size.QuadPart = l_size;
BOOL cur2 = SetFilePointerEx(h, li_size, NULL, FILE_BEGIN);
if (cur2 == 0) {
int error = GetLastError();
uError("SetFilePointerEx GetLastError is: %d\n", error);
switch (error) {
case ERROR_INVALID_HANDLE:
errno = EBADF;
break;
default:
errno = EIO;
break;
}
return -1;
}
if (!SetEndOfFile(h)) {
int error = GetLastError();
uError("SetEndOfFile GetLastError is:%d", error);
switch (error) {
case ERROR_INVALID_HANDLE:
errno = EBADF;
break;
default:
errno = EIO;
break;
}
return -1;
}
return 0;
}
int32_t taosFsync(FileFd fd) {
if (fd < 0) {
errno = EBADF;
uError("%s\n", "fd arg was negative");
return -1;
}
HANDLE h = (HANDLE)_get_osfhandle(fd);
return FlushFileBuffers(h);
}
int32_t taosRename(char *oldName, char *newName) {
int32_t code = MoveFileEx(oldName, newName, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
if (code < 0) {
uError("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno));
} else {
uTrace("successfully to rename file %s to %s", oldName, newName);
}
return code;
}
#else
int32_t taosFtruncate(FileFd fd, int64_t length) { return ftruncate(fd, length); }
int32_t taosFsync(FileFd fd) { return fsync(fd); }
int32_t taosRename(char *oldName, char *newName) {
int32_t code = rename(oldName, newName);
if (code < 0) {
uError("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno));
} else {
uTrace("successfully to rename file %s to %s", oldName, newName);
}
int32_t taosFtruncate(int32_t fd, int64_t length) {
return ftruncate(fd, length);
return code;
}
#endif
......@@ -16,8 +16,6 @@
#define _DEFAULT_SOURCE
#include "os.h"
#ifndef TAOS_OS_FUNC_RAND
uint32_t taosRand(void) { return rand(); }
uint32_t taosSafeRand(void) {
......@@ -38,8 +36,6 @@ uint32_t taosSafeRand(void) {
return (uint32_t)seed;
}
#endif
void taosRandStr(char* str, int32_t size) {
const char* set = "abcdefghijklmnopqrstuvwxyz0123456789-_.";
int32_t len = 39;
......
......@@ -16,9 +16,9 @@
#define _DEFAULT_SOURCE
#include "os.h"
#ifndef TAOS_OS_FUNC_SEMPHONE
#if !defined (_TD_DARWIN_64)
int tsem_wait(tsem_t* sem) {
int32_t tsem_wait(tsem_t* sem) {
int ret = 0;
do {
ret = sem_wait(sem);
......@@ -28,7 +28,7 @@ int tsem_wait(tsem_t* sem) {
#endif
#ifndef TAOS_OS_FUNC_SEMPHONE_PTHREAD
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined (_TD_DARWIN_64))
bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; }
......
......@@ -15,11 +15,13 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "taosdef.h"
#include "tconfig.h"
#include "tglobal.h"
#include "tulog.h"
#ifndef TAOS_OS_FUNC_SIGNAL
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
typedef void (*FLinuxSignalHandler)(int32_t signum, siginfo_t *sigInfo, void *context);
void taosSetSignal(int32_t signum, FSignalHandler sigfp) {
......
......@@ -15,19 +15,43 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "taosdef.h"
#include "tglobal.h"
#include "ttimer.h"
#include "tulog.h"
#include "tutil.h"
#ifdef _TD_GO_DLL_
int64_t tsosStr2int64(char *str) {
char *endptr = NULL;
return strtoll(str, &endptr, 10);
}
uint64_t htonll(uint64_t val) {
return (((uint64_t) htonl(val)) << 32) + htonl(val >> 32);
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
void taosMsleep(int32_t ms) { Sleep(ms); }
#else
/*
to make taosMsleep work,
signal SIGALRM shall be blocked in the calling thread,
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGALRM);
pthread_sigmask(SIG_BLOCK, &set, NULL);
*/
void taosMsleep(int32_t mseconds) {
#if 1
usleep(mseconds * 1000);
#else
struct timeval timeout;
int32_t seconds, useconds;
seconds = mseconds / 1000;
useconds = (mseconds % 1000) * 1000;
timeout.tv_sec = seconds;
timeout.tv_usec = useconds;
/* sigset_t set; */
/* sigemptyset(&set); */
/* sigaddset(&set, SIGALRM); */
/* pthread_sigmask(SIG_BLOCK, &set, NULL); */
select(0, NULL, NULL, NULL, &timeout);
/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */
#endif
}
#endif
......@@ -17,7 +17,7 @@
#include "os.h"
#include "tulog.h"
#ifndef TAOS_OS_FUNC_SOCKET
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
int32_t taosSetNonblocking(SOCKET sock, int32_t on) {
int32_t flags = 0;
......@@ -65,7 +65,7 @@ void taosSetMaskSIGPIPE() {
#endif
#ifndef TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined(_TD_DARWIN_32))
int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t optlen) {
return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen);
......@@ -74,9 +74,10 @@ int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op
int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t* optlen) {
return getsockopt(socketfd, level, optname, optval, (socklen_t *)optlen);
}
#endif
#ifndef TAOS_OS_FUNC_SOCKET_INET
#if !( (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) && defined(_MSC_VER) )
uint32_t taosInetAddr(char *ipAddr) {
return inet_addr(ipAddr);
......
......@@ -17,17 +17,17 @@
#include "os.h"
#include "tglobal.h"
#ifndef TAOS_OS_FUNC_STRING_STR2INT64
int64_t tsosStr2int64(char *str) {
int64_t taosStr2int64(char *str) {
char *endptr = NULL;
return strtoll(str, &endptr, 10);
}
#endif
#ifndef TAOS_OS_FUNC_STRING_WCHAR
int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) {
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) {
return wcsncmp((wchar_t *)f1_ucs4, (wchar_t *)f2_ucs4, bytes / TSDB_NCHAR_SIZE);
}
#endif
#ifdef USE_LIBICONV
......
......@@ -20,7 +20,7 @@
#include "tulog.h"
#include "taoserror.h"
#ifndef TAOS_OS_FUNC_SYSINFO
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined (_TD_DARWIN_64))
#define PROCESS_ITEM 12
......
......@@ -18,7 +18,7 @@
#include "ttimer.h"
#include "tulog.h"
#ifndef TAOS_OS_FUNC_TIMER
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined(_TD_DARWIN_64))
static void taosDeleteTimer(void *tharg) {
timer_t *pTimer = tharg;
......@@ -104,42 +104,3 @@ void taosUninitTimer() {
}
#endif
#ifndef TAOS_OS_FUNC_TIMER_SLEEP
/*
to make taosMsleep work,
signal SIGALRM shall be blocked in the calling thread,
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGALRM);
pthread_sigmask(SIG_BLOCK, &set, NULL);
*/
void taosMsleep(int mseconds) {
#ifdef __APPLE__
taos_block_sigalrm();
#endif // __APPLE__
#if 1
usleep(mseconds * 1000);
#else
struct timeval timeout;
int seconds, useconds;
seconds = mseconds / 1000;
useconds = (mseconds % 1000) * 1000;
timeout.tv_sec = seconds;
timeout.tv_usec = useconds;
/* sigset_t set; */
/* sigemptyset(&set); */
/* sigaddset(&set, SIGALRM); */
/* pthread_sigmask(SIG_BLOCK, &set, NULL); */
select(0, NULL, NULL, NULL, &timeout);
/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */
#endif
}
#endif
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "osSocket.h"
#include "tglobal.h"
#include "tulog.h"
void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) {
const char *tdengineTmpFileNamePrefix = "tdengine-";
char tmpPath[PATH_MAX];
int32_t len = (int32_t)strlen(tsTempDir);
memcpy(tmpPath, tsTempDir, len);
if (tmpPath[len - 1] != '/' && tmpPath[len - 1] != '\\') {
tmpPath[len++] = '\\';
}
strcpy(tmpPath + len, tdengineTmpFileNamePrefix);
strcat(tmpPath, tdengineTmpFileNamePrefix);
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
strcat(tmpPath, fileNamePrefix);
strcat(tmpPath, "-%d-%s");
}
char rand[8] = {0};
taosRandStr(rand, tListLen(rand) - 1);
snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand);
}
#define _SEND_FILE_STEP_ 1000
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;
}
}
return writeLen;
}
int64_t taosSendFile(SOCKET dfd, int32_t sfd, int64_t *offset, int64_t count) {
if (offset != NULL) lseek(sfd, (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_) {
int32_t rlen = (int32_t)read(sfd, buffer, _SEND_FILE_STEP_);
if (rlen <= 0) {
return writeLen;
} else if (rlen < _SEND_FILE_STEP_) {
taosWriteSocket(dfd, buffer, rlen);
return (int64_t)(writeLen + rlen);
} else {
taosWriteSocket(dfd, buffer, _SEND_FILE_STEP_);
writeLen += _SEND_FILE_STEP_;
}
}
int64_t remain = count - writeLen;
if (remain > 0) {
int32_t rlen = read(sfd, buffer, (int32_t)remain);
if (rlen <= 0) {
return writeLen;
} else {
taosWriteSocket(sfd, buffer, (int32_t)remain);
writeLen += remain;
}
}
return writeLen;
}
int32_t taosFtruncate(int32_t fd, int64_t l_size) {
if (fd < 0) {
errno = EBADF;
uError("%s\n", "fd arg was negative");
return -1;
}
HANDLE h = (HANDLE)_get_osfhandle(fd);
LARGE_INTEGER li_0;
li_0.QuadPart = (int64_t)0;
BOOL cur = SetFilePointerEx(h, li_0, NULL, FILE_CURRENT);
if (!cur) {
uError("SetFilePointerEx Error getting current position in file.\n");
return -1;
}
LARGE_INTEGER li_size;
li_size.QuadPart = l_size;
BOOL cur2 = SetFilePointerEx(h, li_size, NULL, FILE_BEGIN);
if (cur2 == 0) {
int error = GetLastError();
uError("SetFilePointerEx GetLastError is: %d\n", error);
switch (error) {
case ERROR_INVALID_HANDLE:
errno = EBADF;
break;
default:
errno = EIO;
break;
}
return -1;
}
if (!SetEndOfFile(h)) {
int error = GetLastError();
uError("SetEndOfFile GetLastError is:%d", error);
switch (error) {
case ERROR_INVALID_HANDLE:
errno = EBADF;
break;
default:
errno = EIO;
break;
}
return -1;
}
return 0;
}
int fsync(int filedes) {
if (filedes < 0) {
errno = EBADF;
uError("%s\n", "fd arg was negative");
return -1;
}
HANDLE h = (HANDLE)_get_osfhandle(filedes);
return FlushFileBuffers(h);
}
int32_t taosRename(char* oldName, char *newName) {
int32_t code = MoveFileEx(oldName, newName, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
if (code < 0) {
uError("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno));
} else {
uTrace("successfully to rename file %s to %s", oldName, newName);
}
return code;
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ General Public License for more details. */
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#if STDC_HEADERS
#include <stdlib.h>
......@@ -40,10 +41,10 @@ null terminator), or -1 on error or EOF. On a -1 return, the caller
should check feof(), if not then errno has been set to indicate
the error. */
int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) {
int nchars_avail; /* Allocated but unused chars in *LINEPTR. */
char *read_pos; /* Where we're reading into *LINEPTR. */
int ret;
int32_t getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int32_t offset) {
int32_t nchars_avail; /* Allocated but unused chars in *LINEPTR. */
char * read_pos; /* Where we're reading into *LINEPTR. */
int32_t ret;
if (!lineptr || !n || !stream) {
errno = EINVAL;
......@@ -59,12 +60,12 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset)
}
}
nchars_avail = (int)(*n - offset);
nchars_avail = (int32_t)(*n - offset);
read_pos = *lineptr + offset;
for (;;) {
int save_errno;
register int c = getc(stream);
int32_t save_errno;
register int32_t c = getc(stream);
save_errno = errno;
......@@ -79,7 +80,7 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset)
else
*n += MIN_CHUNK;
nchars_avail = (int)(*n + *lineptr - read_pos);
nchars_avail = (int32_t)(*n + *lineptr - read_pos);
*lineptr = realloc(*lineptr, *n);
if (!*lineptr) {
errno = ENOMEM;
......@@ -115,10 +116,8 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset)
/* Done - NUL terminate and return the number of chars read. */
*read_pos = '\0';
ret = (int)(read_pos - (*lineptr + offset));
ret = (int32_t)(read_pos - (*lineptr + offset));
return ret;
}
int taosGetlineImp(char **lineptr, size_t *n, FILE *stream) {
return getstr(lineptr, n, stream, '\n', 0);
}
\ No newline at end of file
int32_t tgetline(char **lineptr, size_t *n, FILE *stream) { return getstr(lineptr, n, stream, '\n', 0); }
\ No newline at end of file
......@@ -70,7 +70,8 @@ int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op
return setsockopt(socketfd, level, optname, optval, optlen);
}
#ifdef TAOS_OS_FUNC_SOCKET_INET
#ifdef _MSC_VER
//#if _MSC_VER >= 1900
uint32_t taosInetAddr(char *ipAddr) {
uint32_t value;
......@@ -88,4 +89,11 @@ const char *taosInetNtoa(struct in_addr ipInt) {
return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN);
}
//#endif
#endif
#if defined(_TD_GO_DLL_)
uint64_t htonll(uint64_t val) { return (((uint64_t)htonl(val)) << 32) + htonl(val >> 32); }
#endif
......@@ -33,9 +33,9 @@
* If *stringp is NULL, strsep returns NULL.
*/
char *strsep(char **stringp, const char *delim) {
char *s;
char * s;
const char *spanp;
int c, sc;
int32_t c, sc;
char *tok;
if ((s = *stringp) == NULL)
return (NULL);
......@@ -75,13 +75,13 @@ char *getpass(const char *prefix) {
return passwd;
}
int twcslen(const wchar_t *wcs) {
int *wstr = (int *)wcs;
int32_t twcslen(const wchar_t *wcs) {
int32_t *wstr = (int32_t *)wcs;
if (NULL == wstr) {
return 0;
}
int n = 0;
int32_t n = 0;
while (1) {
if (0 == *wstr++) {
break;
......@@ -92,8 +92,8 @@ int twcslen(const wchar_t *wcs) {
return n;
}
int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) {
for (int i = 0; i < bytes; ++i) {
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) {
for (int32_t i = 0; i < bytes; ++i) {
int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i * 4);
int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i * 4);
......@@ -127,7 +127,6 @@ int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) {
#endif
}
/* Copy memory to memory until the specified number of bytes
has been copied, return pointer to following byte.
Overlap is NOT handled correctly. */
......
......@@ -43,7 +43,3 @@ int taosInitTimer(win_timer_f callback, int ms) {
void taosUninitTimer() {
timeKillEvent(timerId);
}
void taosMsleep(int mseconds) {
Sleep(mseconds);
}
......@@ -484,7 +484,7 @@ void tsBufFlush(STSBuf* pTSBuf) {
.magic = TS_COMP_FILE_MAGIC, .numOfGroup = pTSBuf->numOfGroups, .tsOrder = pTSBuf->tsOrder};
STSBufUpdateHeader(pTSBuf, &header);
fsync(fileno(pTSBuf->f));
taosFsync(fileno(pTSBuf->f));
}
static int32_t tsBufFindGroupById(STSGroupBlockInfoEx* pGroupInfoEx, int32_t numOfGroups, int32_t id) {
......@@ -868,7 +868,7 @@ STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_
.magic = TS_COMP_FILE_MAGIC, .numOfGroup = pTSBuf->numOfGroups, .tsOrder = pTSBuf->tsOrder};
STSBufUpdateHeader(pTSBuf, &header);
fsync(fileno(pTSBuf->f));
taosFsync(fileno(pTSBuf->f));
return pTSBuf;
}
......
......@@ -529,9 +529,6 @@ static void *taosProcessTcpData(void *param) {
struct epoll_event events[maxEvents];
SRecvInfo recvInfo;
#ifdef __APPLE__
taos_block_sigalrm();
#endif // __APPLE__
while (1) {
int fdNum = epoll_wait(pThreadObj->pollFd, events, maxEvents, TAOS_EPOLL_WAIT_TIME);
if (pThreadObj->stop) {
......
......@@ -52,7 +52,7 @@ void processShellMsg() {
if (commit >=2) {
num += numOfMsgs;
if ( fsync(dataFd) < 0 ) {
if ( taosFsync(dataFd) < 0 ) {
tInfo("failed to flush data to file, reason:%s", strerror(errno));
}
......
......@@ -32,7 +32,7 @@
#define TSDB_FILE_SET_CLOSED(f) (TSDB_FILE_FD(f) = -1)
#define TSDB_FILE_LEVEL(tf) TFILE_LEVEL(TSDB_FILE_F(tf))
#define TSDB_FILE_ID(tf) TFILE_ID(TSDB_FILE_F(tf))
#define TSDB_FILE_FSYNC(tf) fsync(TSDB_FILE_FD(tf))
#define TSDB_FILE_FSYNC(tf) taosFsync(TSDB_FILE_FD(tf))
#define TSDB_FILE_STATE(tf) ((tf)->state)
#define TSDB_FILE_SET_STATE(tf, s) ((tf)->state = (s))
#define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK)
......
......@@ -390,7 +390,7 @@ static int tsdbSaveFSStatus(SFSStatus *pStatus, int vid) {
}
// fsync, close and rename
if (fsync(fd) < 0) {
if (taosFsync(fd) < 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
close(fd);
remove(tfname);
......
......@@ -661,11 +661,7 @@ void* taosCacheTimedRefresh(void *handle) {
int64_t count = 0;
while(1) {
#if defined LINUX
usleep(500*1000);
#else
taosMsleep(500);
#endif
// check if current cache object will be deleted every 500ms.
if (pCacheObj->deleting) {
......
......@@ -98,7 +98,7 @@ int32_t tfFsync(int64_t tfd) {
if (p == NULL) return -1;
int32_t fd = (int32_t)(uintptr_t)p;
int32_t code = fsync(fd);
int32_t code = taosFsync(fd);
taosReleaseRef(tsFileRsetId, tfd);
return code;
......
......@@ -362,7 +362,7 @@ int32_t vnodeWriteCfg(SCreateVnodeMsg *pMsg) {
len += snprintf(content + len, maxLen - len, "}\n");
fwrite(content, 1, len, fp);
fsync(fileno(fp));
taosFsync(fileno(fp));
fclose(fp);
free(content);
terrno = 0;
......
......@@ -90,7 +90,7 @@ int32_t vnodeSaveVersion(SVnodeObj *pVnode) {
len += snprintf(content + len, maxLen - len, "}\n");
fwrite(content, 1, len, fp);
fsync(fileno(fp));
taosFsync(fileno(fp));
fclose(fp);
free(content);
terrno = 0;
......
......@@ -20,7 +20,7 @@
// monitor and compare : glances
#ifdef __APPLE__
#include "eok.h"
#include "osEok.h"
#else // __APPLE__
#include <sys/epoll.h>
#endif // __APPLE__
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册