提交 1f3b7197 编写于 作者: S Shengliang Guan

remove some system include files

上级 8ccd079f
...@@ -24,10 +24,8 @@ extern "C" { ...@@ -24,10 +24,8 @@ extern "C" {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
typedef int32_t FileFd; typedef int32_t FileFd;
typedef SOCKET SocketFd;
#else #else
typedef int32_t FileFd; typedef int32_t FileFd;
typedef int32_t SocketFd;
#endif #endif
#define FD_INITIALIZER ((int32_t)-1) #define FD_INITIALIZER ((int32_t)-1)
......
...@@ -27,49 +27,33 @@ extern "C" { ...@@ -27,49 +27,33 @@ extern "C" {
#include <Winsock2.h> #include <Winsock2.h>
#else #else
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <sys/epoll.h> #include <sys/epoll.h>
#include <unistd.h>
#endif #endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #define TAOS_EPOLL_WAIT_TIME 500
#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)
#define taosWriteSocket(fd, buf, len) write(fd, buf, len)
#define taosCloseSocketNoCheck(x) close(x)
#define taosCloseSocket(x) \
{ \
if ((x) > -1) { \
close(x); \
x = FD_INITIALIZER; \
} \
}
#endif
#define TAOS_EPOLL_WAIT_TIME 500
typedef int32_t SOCKET; typedef int32_t SOCKET;
typedef SOCKET EpollFd; typedef SOCKET EpollFd;
#define EpollClose(pollFd) taosCloseSocket(pollFd) #define EpollClose(pollFd) taosCloseSocket(pollFd)
void taosShutDownSocketRD(SOCKET fd); #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
void taosShutDownSocketWR(SOCKET fd); typedef SOCKET SocketFd;
#else
typedef int32_t SocketFd;
#endif
int32_t taosSendto(SocketFd fd, void * msg, int len, unsigned int flags, const struct sockaddr * to, int tolen);
int32_t taosWriteSocket(SocketFd fd, void *msg, int len);
int32_t taosReadSocket(SocketFd fd, void *msg, int len);
int32_t taosCloseSocketNoCheck(SocketFd fd);
int32_t taosCloseSocket(SocketFd fd);
void taosShutDownSocketRD(SOCKET fd);
void taosShutDownSocketWR(SOCKET fd);
int32_t taosSetNonblocking(SOCKET sock, int32_t on); int32_t taosSetNonblocking(SOCKET sock, int32_t on);
void taosIgnSIGPIPE(); void taosIgnSIGPIPE();
void taosBlockSIGPIPE(); void taosBlockSIGPIPE();
void taosSetMaskSIGPIPE(); void taosSetMaskSIGPIPE();
int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t optlen); 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); int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t *optlen);
uint32_t taosInetAddr(char *ipAddr); uint32_t taosInetAddr(char *ipAddr);
const char *taosInetNtoa(struct in_addr ipInt); const char *taosInetNtoa(struct in_addr ipInt);
......
...@@ -66,6 +66,8 @@ typedef struct { ...@@ -66,6 +66,8 @@ typedef struct {
SysNameInfo taosGetSysNameInfo(); SysNameInfo taosGetSysNameInfo();
int64_t taosGetPid();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -695,7 +695,7 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) { ...@@ -695,7 +695,7 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) {
pConn->sid = sid; pConn->sid = sid;
pConn->tranId = (uint16_t)(taosRand() & 0xFFFF); pConn->tranId = (uint16_t)(taosRand() & 0xFFFF);
pConn->ownId = htonl(pConn->sid); pConn->ownId = htonl(pConn->sid);
pConn->linkUid = (uint32_t)((int64_t)pConn + (int64_t)getpid() + (int64_t)pConn->tranId); pConn->linkUid = (uint32_t)((int64_t)pConn + taosGetPid() + (int64_t)pConn->tranId);
pConn->spi = pRpc->spi; pConn->spi = pRpc->spi;
pConn->encrypt = pRpc->encrypt; pConn->encrypt = pRpc->encrypt;
if (pConn->spi) memcpy(pConn->secret, pRpc->secret, TSDB_KEY_LEN); if (pConn->spi) memcpy(pConn->secret, pRpc->secret, TSDB_KEY_LEN);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#else #else
#include <sys/file.h> #include <sys/file.h>
#include <unistd.h>
#endif #endif
uint32_t taosRand(void) { return rand(); } uint32_t taosRand(void) { return rand(); }
......
...@@ -376,6 +376,7 @@ int32_t taosGetCurrentAPPName(char *name, int32_t *len) { ...@@ -376,6 +376,7 @@ int32_t taosGetCurrentAPPName(char *name, int32_t *len) {
*/ */
#include <sys/syscall.h> #include <sys/syscall.h>
#include <unistd.h>
bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; } bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; }
......
...@@ -22,6 +22,8 @@ void taosMsleep(int32_t ms) { Sleep(ms); } ...@@ -22,6 +22,8 @@ void taosMsleep(int32_t ms) { Sleep(ms); }
#else #else
#include <unistd.h>
/* /*
to make taosMsleep work, to make taosMsleep work,
signal SIGALRM shall be blocked in the calling thread, signal SIGALRM shall be blocked in the calling thread,
......
...@@ -17,16 +17,57 @@ ...@@ -17,16 +17,57 @@
#include "os.h" #include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#include "winsock2.h"
#include <WS2tcpip.h>
#include <winbase.h>
#include <Winsock2.h>
#else #else
#include <arpa/inet.h> #include <arpa/inet.h>
#include <fcntl.h> #include <fcntl.h>
#include <netdb.h> #include <netdb.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/ip.h> #include <netinet/ip.h>
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <netinet/udp.h> #include <netinet/udp.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define taosSend(sockfd, buf, len, flags) send((SOCKET)sockfd, buf, len, flags)
int32_t taosSendto(SocketFd fd, void *buf, int len, unsigned int flags, const struct sockaddr *to, int tolen) {
return sendto((SOCKET)sockfd, buf, len, flags, dest_addr, addrlen);
}
int32_t taosWriteSocket(SocketFd fd, void *buf, int len) { return send((SOCKET)fd, buf, len, 0); }
int32_t taosReadSocket(SocketFd fd, void *buf, int len) { return recv((SOCKET)fd, buf, len, 0)(); }
int32_t taosCloseSocketNoCheck(SocketFd fd) { return closesocket((SOCKET)fd); }
int32_t taosCloseSocket(SocketFd fd) { closesocket((SOCKET)fd) }
#else
#define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
int32_t taosSendto(SocketFd fd, void * buf, int len, unsigned int flags, const struct sockaddr * dest_addr, int addrlen) {
return sendto(fd, buf, len, flags, dest_addr, addrlen);
}
int32_t taosWriteSocket(SocketFd fd, void *buf, int len) {
return write(fd, buf, len);
}
int32_t taosReadSocket(SocketFd fd, void *buf, int len) {
return read(fd, buf, len);
}
int32_t taosCloseSocketNoCheck(SocketFd fd) {
return close(fd);
}
int32_t taosCloseSocket(SocketFd fd) {
if (fd > -1) {
close(fd);
}
}
#endif #endif
void taosShutDownSocketRD(SOCKET fd) { void taosShutDownSocketRD(SOCKET fd) {
...@@ -226,8 +267,6 @@ uint64_t htonll(uint64_t val) { return (((uint64_t)htonl(val)) << 32) + htonl(va ...@@ -226,8 +267,6 @@ uint64_t htonll(uint64_t val) { return (((uint64_t)htonl(val)) << 32) + htonl(va
#endif #endif
#ifndef SIGPIPE #ifndef SIGPIPE
#define SIGPIPE EPIPE #define SIGPIPE EPIPE
#endif #endif
......
...@@ -485,6 +485,7 @@ char *taosGetCmdlineByPID(int pid) { ...@@ -485,6 +485,7 @@ char *taosGetCmdlineByPID(int pid) {
#include <sys/statvfs.h> #include <sys/statvfs.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <unistd.h>
#define PROCESS_ITEM 12 #define PROCESS_ITEM 12
...@@ -1127,4 +1128,9 @@ SysNameInfo taosGetSysNameInfo() { ...@@ -1127,4 +1128,9 @@ SysNameInfo taosGetSysNameInfo() {
return info; return info;
} }
int64_t taosGetPid() {
getpid();
}
#endif #endif
\ No newline at end of file
...@@ -62,6 +62,7 @@ void taosUninitTimer() { ...@@ -62,6 +62,7 @@ void taosUninitTimer() {
#include <sys/syscall.h> #include <sys/syscall.h>
#include <sys/event.h> #include <sys/event.h>
#include <unistd.h>
static void (*timer_callback)(int); static void (*timer_callback)(int);
static int timer_ms = 0; static int timer_ms = 0;
...@@ -136,6 +137,7 @@ void taos_block_sigalrm(void) { ...@@ -136,6 +137,7 @@ void taos_block_sigalrm(void) {
*/ */
#include <sys/syscall.h> #include <sys/syscall.h>
#include <unistd.h>
static void taosDeleteTimer(void *tharg) { static void taosDeleteTimer(void *tharg) {
timer_t *pTimer = tharg; timer_t *pTimer = tharg;
......
...@@ -210,7 +210,7 @@ static void dnodeSendTelemetryReport(DnTelem* telem) { ...@@ -210,7 +210,7 @@ static void dnodeSendTelemetryReport(DnTelem* telem) {
"Content-Type: application/json\n" "Content-Type: application/json\n"
"Content-Length: "; "Content-Length: ";
taosWriteSocket(fd, header, (int32_t)strlen(header)); taosWriteSocket(fd, (void*)header, (int32_t)strlen(header));
int32_t contLen = (int32_t)(tbufTell(&bw) - 1); int32_t contLen = (int32_t)(tbufTell(&bw) - 1);
sprintf(buf, "%d\n\n", contLen); sprintf(buf, "%d\n\n", contLen);
taosWriteSocket(fd, buf, (int32_t)strlen(buf)); taosWriteSocket(fd, buf, (int32_t)strlen(buf));
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
static int32_t tsFileRsetId = -1; static int32_t tsFileRsetId = -1;
static void tfCloseFile(void *p) { static void tfCloseFile(void *p) {
close((int32_t)(uintptr_t)p); taosCloseFile((int32_t)(uintptr_t)p);
} }
int32_t tfInit() { int32_t tfInit() {
...@@ -48,7 +48,7 @@ static int64_t tfOpenImp(int32_t fd) { ...@@ -48,7 +48,7 @@ static int64_t tfOpenImp(int32_t fd) {
void * p = (void *)(int64_t)fd; void * p = (void *)(int64_t)fd;
int64_t rid = taosAddRef(tsFileRsetId, p); int64_t rid = taosAddRef(tsFileRsetId, p);
if (rid < 0) close(fd); if (rid < 0) taosCloseFile(fd);
return rid; return rid;
} }
......
...@@ -100,7 +100,7 @@ static void *taosThreadToOpenNewNote(void *param) { ...@@ -100,7 +100,7 @@ static void *taosThreadToOpenNewNote(void *param) {
} }
taosLockNote(fd, pNote); taosLockNote(fd, pNote);
(void)lseek(fd, 0, SEEK_SET); (void)taosLSeekFile(fd, 0, SEEK_SET);
int32_t oldFd = pNote->fd; int32_t oldFd = pNote->fd;
pNote->fd = fd; pNote->fd = fd;
...@@ -142,10 +142,10 @@ static bool taosCheckNoteIsOpen(char *noteName, SNoteObj *pNote) { ...@@ -142,10 +142,10 @@ static bool taosCheckNoteIsOpen(char *noteName, SNoteObj *pNote) {
if (taosLockNote(fd, pNote)) { if (taosLockNote(fd, pNote)) {
taosUnLockNote(fd, pNote); taosUnLockNote(fd, pNote);
close(fd); taosCloseFile(fd);
return false; return false;
} else { } else {
close(fd); taosCloseFile(fd);
return true; return true;
} }
} }
...@@ -226,7 +226,7 @@ static int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxN ...@@ -226,7 +226,7 @@ static int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxN
size = (int32_t)filestat_size; size = (int32_t)filestat_size;
pNote->lines = size / 60; pNote->lines = size / 60;
lseek(pNote->fd, 0, SEEK_END); taosLSeekFile(pNote->fd, 0, SEEK_END);
return 0; return 0;
} }
...@@ -271,6 +271,6 @@ void taosNotePrint(SNoteObj *pNote, const char *const format, ...) { ...@@ -271,6 +271,6 @@ void taosNotePrint(SNoteObj *pNote, const char *const format, ...) {
static void taosCloseNoteByFd(int32_t fd, SNoteObj *pNote) { static void taosCloseNoteByFd(int32_t fd, SNoteObj *pNote) {
if (fd >= 0) { if (fd >= 0) {
taosUnLockNote(fd, pNote); taosUnLockNote(fd, pNote);
close(fd); taosCloseFile(fd);
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册