From afb33efc6a63fd4bba5329109c6cacb12b997818 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Mon, 4 Nov 2019 17:59:57 +0800 Subject: [PATCH] configure the connection option through taos_options #671 --- packaging/cfg/taos.cfg | 5 +++-- src/client/src/tscSystem.c | 15 +++++++++++++++ src/inc/taos.h | 1 + src/inc/tglobalcfg.h | 2 +- src/inc/trpc.h | 7 +++++-- src/util/src/tglobalcfg.c | 7 +++---- 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/packaging/cfg/taos.cfg b/packaging/cfg/taos.cfg index 3f7ece8826..2cd7af1dd3 100644 --- a/packaging/cfg/taos.cfg +++ b/packaging/cfg/taos.cfg @@ -54,8 +54,9 @@ # interval of system monitor # monitorInterval 60 -# set socket type(UDP by default). if udpsocket is 0, TCP is applied for all connections -# udpsocket 1 +# set socket type("udp" and "tcp"). +# The server and client should have the same socket type. Otherwise, connect will fail. +# sockettype udp # RPC re-try timer, millisecond # rpcTimer 300 diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index ff0c1555ff..ecb21db4de 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -174,6 +174,7 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { SGlobalConfig *cfg_locale = tsGetConfigOption("locale"); SGlobalConfig *cfg_charset = tsGetConfigOption("charset"); SGlobalConfig *cfg_timezone = tsGetConfigOption("timezone"); + SGlobalConfig *cfg_socket = tsGetConfigOption("sockettype"); switch (option) { case TSDB_OPTION_CONFIGDIR: @@ -304,6 +305,20 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { tsCfgStatusStr[cfg_timezone->cfgStatus], (char *)cfg_timezone->ptr); } break; + + case TSDB_OPTION_SOCKET_TYPE: + if (cfg_socket && cfg_socket->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { + if (strcasecmp(arg, TAOS_SOCKET_TYPE_NAME_UDP) != 0 && strcasecmp(arg, TAOS_SOCKET_TYPE_NAME_TCP) != 0) { + tscError("only 'tcp' or 'udp' allowed for configuring the socket type"); + return -1; + } + + strncpy(tsSocketType, arg, tListLen(tsSocketType)); + cfg_socket->cfgStatus = TSDB_CFG_CSTATUS_OPTION; + tscPrint("socket type is set:%s", tsSocketType); + } + break; + default: tscError("Invalid option %d", option); return -1; diff --git a/src/inc/taos.h b/src/inc/taos.h index bee0dcab1c..3af3a0ab75 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -46,6 +46,7 @@ typedef enum { TSDB_OPTION_TIMEZONE, TSDB_OPTION_CONFIGDIR, TSDB_OPTION_SHELL_ACTIVITY_TIMER, + TSDB_OPTION_SOCKET_TYPE, TSDB_MAX_OPTIONS } TSDB_OPTION; diff --git a/src/inc/tglobalcfg.h b/src/inc/tglobalcfg.h index 054317fcae..95a3cc57e2 100644 --- a/src/inc/tglobalcfg.h +++ b/src/inc/tglobalcfg.h @@ -132,7 +132,7 @@ extern int tsStreamCompRetryDelay; extern int tsProjectExecInterval; extern int64_t tsMaxRetentWindow; -extern int tsUDPSocket; +extern char tsSocketType[4]; extern char tsHttpIp[]; extern short tsHttpPort; diff --git a/src/inc/trpc.h b/src/inc/trpc.h index 0532f1c129..f849d15d06 100644 --- a/src/inc/trpc.h +++ b/src/inc/trpc.h @@ -30,12 +30,15 @@ extern "C" { #define TAOS_CONN_HTTPS 4 #define TAOS_CONN_HTTPC 5 +#define TAOS_SOCKET_TYPE_NAME_TCP "tcp" +#define TAOS_SOCKET_TYPE_NAME_UDP "udp" + #define TAOS_ID_ASSIGNED 0 #define TAOS_ID_FREE 1 #define TAOS_ID_REALLOCATE 2 -#define TAOS_CONN_SOCKET_TYPE_S() ((tsUDPSocket == 1)? TAOS_CONN_UDPS:TAOS_CONN_TCPS) -#define TAOS_CONN_SOCKET_TYPE_C() ((tsUDPSocket == 1)? TAOS_CONN_UDP:TAOS_CONN_TCPC) +#define TAOS_CONN_SOCKET_TYPE_S() ((strcasecmp(tsSocketType, TAOS_SOCKET_TYPE_NAME_UDP) == 0)? TAOS_CONN_UDPS:TAOS_CONN_TCPS) +#define TAOS_CONN_SOCKET_TYPE_C() ((strcasecmp(tsSocketType, TAOS_SOCKET_TYPE_NAME_UDP) == 0)? TAOS_CONN_UDP:TAOS_CONN_TCPC) #define taosSendMsgToPeer(x, y, z) taosSendMsgToPeerH(x, y, z, NULL) #define taosOpenRpcChann(x, y, z) taosOpenRpcChannWithQ(x, y, z, NULL) diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index f26732e688..9fd065e90a 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -122,8 +122,7 @@ int tsStreamCompRetryDelay = 10; // the stream computing delay int tsProjectExecInterval = 10000; // every 10sec, the projection will be executed once int64_t tsMaxRetentWindow = 24 * 3600L; // maximum time window tolerance -int tsUDPSocket = 1; // use UDP by default, if tsUDPSocket equals to 0, all connection use TCP socket - +char tsSocketType[4] = "udp"; // use UDP by default[option: udp, tcp] char tsHttpIp[TSDB_IPv4ADDR_LEN] = "0.0.0.0"; short tsHttpPort = 6020; // only tcp, range tcp[6020] // short tsNginxPort = 6060; //only tcp, range tcp[6060] @@ -500,8 +499,8 @@ void tsInitGlobalConfig() { TSDB_PASSWORD_LEN, TSDB_CFG_UTYPE_NONE); // socket type, udp by default - tsInitConfigOption(cfg++, "udpsocket", &tsUDPSocket, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW, 0, 1, 1, TSDB_CFG_UTYPE_NONE); + tsInitConfigOption(cfg++, "sockettype", tsSocketType, TSDB_CFG_VTYPE_STRING, + TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW, 0, 0, 3, TSDB_CFG_UTYPE_NONE); // locale & charset tsInitConfigOption(cfg++, "timezone", tsTimezone, TSDB_CFG_VTYPE_STRING, -- GitLab