未验证 提交 ebb98e4e 编写于 作者: Y Yang Zhao 提交者: GitHub

fix: do not show any ws info in websocket in not defined (#15293)

上级 5a1412f4
...@@ -51,7 +51,6 @@ typedef struct SShellArguments { ...@@ -51,7 +51,6 @@ typedef struct SShellArguments {
char* auth; char* auth;
char* database; char* database;
char* timezone; char* timezone;
bool restful;
TAOS* con; TAOS* con;
bool is_raw_time; bool is_raw_time;
bool is_use_passwd; bool is_use_passwd;
...@@ -69,10 +68,11 @@ typedef struct SShellArguments { ...@@ -69,10 +68,11 @@ typedef struct SShellArguments {
char* netTestRole; char* netTestRole;
char* dsn; char* dsn;
#ifdef WEBSOCKET #ifdef WEBSOCKET
bool restful;
WS_TAOS* ws_conn; WS_TAOS* ws_conn;
#endif
bool cloud; bool cloud;
uint32_t timeout; uint32_t timeout;
#endif
} SShellArguments; } SShellArguments;
/**************** Function declarations ****************/ /**************** Function declarations ****************/
......
...@@ -60,12 +60,14 @@ void printHelp() { ...@@ -60,12 +60,14 @@ void printHelp() {
printf("%s%s%s\n", indent, indent, "Use multi-thread to import all SQL files in the directory separately."); printf("%s%s%s\n", indent, indent, "Use multi-thread to import all SQL files in the directory separately.");
printf("%s%s\n", indent, "-T"); printf("%s%s\n", indent, "-T");
printf("%s%s%s\n", indent, indent, "Number of threads when using multi-thread to import data."); printf("%s%s%s\n", indent, indent, "Number of threads when using multi-thread to import data.");
#ifdef WEBSOCKET
printf("%s%s\n", indent, "-R"); printf("%s%s\n", indent, "-R");
printf("%s%s%s\n", indent, indent, "Connect and interact with TDengine use restful."); printf("%s%s%s\n", indent, indent, "Connect and interact with TDengine use restful.");
printf("%s%s\n", indent, "-E"); printf("%s%s\n", indent, "-E");
printf("%s%s%s\n", indent, indent, "The DSN to use when connecting TDengine's cloud services."); printf("%s%s%s\n", indent, indent, "The DSN to use when connecting TDengine's cloud services.");
printf("%s%s\n", indent, "-t"); printf("%s%s\n", indent, "-t");
printf("%s%s%s\n", indent, indent, "The timeout in seconds for websocket interact."); printf("%s%s%s\n", indent, indent, "The timeout in seconds for websocket interact.");
#endif
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
...@@ -79,7 +81,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -79,7 +81,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
// for host // for host
if (strcmp(argv[i], "-h") == 0) { if (strcmp(argv[i], "-h") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
#ifdef WEBSOCKET
arguments->cloud = false; arguments->cloud = false;
#endif
arguments->host = argv[++i]; arguments->host = argv[++i];
} else { } else {
fprintf(stderr, "option -h requires an argument\n"); fprintf(stderr, "option -h requires an argument\n");
...@@ -111,7 +115,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -111,7 +115,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
// for management port // for management port
else if (strcmp(argv[i], "-P") == 0) { else if (strcmp(argv[i], "-P") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
#ifdef WEBSOCKET
arguments->cloud = false; arguments->cloud = false;
#endif
arguments->port = atoi(argv[++i]); arguments->port = atoi(argv[++i]);
} else { } else {
fprintf(stderr, "option -P requires an argument\n"); fprintf(stderr, "option -P requires an argument\n");
...@@ -128,7 +134,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -128,7 +134,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
} }
} else if (strcmp(argv[i], "-c") == 0) { } else if (strcmp(argv[i], "-c") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
#ifdef WEBSOCKET
arguments->cloud = false; arguments->cloud = false;
#endif
if (strlen(argv[++i]) >= TSDB_FILENAME_LEN) { if (strlen(argv[++i]) >= TSDB_FILENAME_LEN) {
fprintf(stderr, "config file path: %s overflow max len %d\n", argv[i], TSDB_FILENAME_LEN - 1); fprintf(stderr, "config file path: %s overflow max len %d\n", argv[i], TSDB_FILENAME_LEN - 1);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -198,7 +206,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -198,7 +206,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
#ifdef WEBSOCKET
else if (strcmp(argv[i], "-R") == 0) { else if (strcmp(argv[i], "-R") == 0) {
arguments->cloud = false; arguments->cloud = false;
arguments->restful = true; arguments->restful = true;
...@@ -221,6 +229,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -221,6 +229,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
#endif
// For temperory command TODO // For temperory command TODO
else if (strcmp(argv[i], "--help") == 0) { else if (strcmp(argv[i], "--help") == 0) {
...@@ -232,6 +241,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -232,6 +241,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
#ifdef WEBSOCKET
if (args.dsn == NULL) { if (args.dsn == NULL) {
if (args.cloud) { if (args.cloud) {
args.dsn = getenv("TDENGINE_CLOUD_DSN"); args.dsn = getenv("TDENGINE_CLOUD_DSN");
...@@ -242,6 +252,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -242,6 +252,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
} else { } else {
args.cloud = true; args.cloud = true;
} }
#endif
} }
int32_t shellReadCommand(TAOS *con, char *command) { int32_t shellReadCommand(TAOS *con, char *command) {
......
...@@ -52,9 +52,11 @@ static struct argp_option options[] = { ...@@ -52,9 +52,11 @@ static struct argp_option options[] = {
{"pktlen", 'l', "PKTLEN", 0, "Packet length used for net test, default is 1000 bytes."}, {"pktlen", 'l', "PKTLEN", 0, "Packet length used for net test, default is 1000 bytes."},
{"pktnum", 'N', "PKTNUM", 0, "Packet numbers used for net test, default is 100."}, {"pktnum", 'N', "PKTNUM", 0, "Packet numbers used for net test, default is 100."},
{"pkttype", 'S', "PKTTYPE", 0, "Choose packet type used for net test, default is TCP. Only speed test could be either TCP or UDP."}, {"pkttype", 'S', "PKTTYPE", 0, "Choose packet type used for net test, default is TCP. Only speed test could be either TCP or UDP."},
#ifdef WEBSOCKET
{"restful", 'R', 0, 0, "Connect and interact with TDengine use restful."}, {"restful", 'R', 0, 0, "Connect and interact with TDengine use restful."},
{"cloudDsn", 'E', "DSN", 0, "The DSN to use when connecting TDengine's cloud services."}, {"cloudDsn", 'E', "DSN", 0, "The DSN to use when connecting TDengine's cloud services."},
{"timeout", 't', "SECONDS", 0, "The timeout seconds for websocket to interact."}, {"timeout", 't', "SECONDS", 0, "The timeout seconds for websocket to interact."},
#endif
{0}}; {0}};
static error_t parse_opt(int key, char *arg, struct argp_state *state) { static error_t parse_opt(int key, char *arg, struct argp_state *state) {
...@@ -66,7 +68,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -66,7 +68,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
switch (key) { switch (key) {
case 'h': case 'h':
if (arg) { if (arg) {
#ifdef WEBSOCKET
args.cloud = false; args.cloud = false;
#endif
args.host = arg; args.host = arg;
} else { } else {
fprintf(stderr, "Invalid host\n"); fprintf(stderr, "Invalid host\n");
...@@ -77,7 +81,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -77,7 +81,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
break; break;
case 'P': case 'P':
if (arg) { if (arg) {
#ifdef WEBSOCKET
args.cloud = false; args.cloud = false;
#endif
tsDnodeShellPort = atoi(arg); tsDnodeShellPort = atoi(arg);
args.port = atoi(arg); args.port = atoi(arg);
} else { } else {
...@@ -105,7 +111,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -105,7 +111,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
wordfree(&full_path); wordfree(&full_path);
return -1; return -1;
} }
#ifdef WEBSOCKET
args.cloud = false; args.cloud = false;
#endif
tstrncpy(configDir, full_path.we_wordv[0], TSDB_FILENAME_LEN); tstrncpy(configDir, full_path.we_wordv[0], TSDB_FILENAME_LEN);
wordfree(&full_path); wordfree(&full_path);
break; break;
...@@ -173,6 +181,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -173,6 +181,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
case OPT_ABORT: case OPT_ABORT:
arguments->abort = 1; arguments->abort = 1;
break; break;
#ifdef WEBSOCKET
case 'R': case 'R':
arguments->restful = true; arguments->restful = true;
arguments->cloud = false; arguments->cloud = false;
...@@ -192,6 +201,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -192,6 +201,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
fprintf(stderr, "Invalid -t option\n"); fprintf(stderr, "Invalid -t option\n");
} }
break; break;
#endif
default: default:
return ARGP_ERR_UNKNOWN; return ARGP_ERR_UNKNOWN;
} }
...@@ -245,6 +255,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -245,6 +255,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
argp_parse(&argp, argc, argv, 0, 0, arguments); argp_parse(&argp, argc, argv, 0, 0, arguments);
#ifdef WEBSOCKET
if (args.dsn == NULL) { if (args.dsn == NULL) {
if (args.cloud) { if (args.cloud) {
args.dsn = getenv("TDENGINE_CLOUD_DSN"); args.dsn = getenv("TDENGINE_CLOUD_DSN");
...@@ -255,6 +266,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -255,6 +266,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
} else { } else {
args.cloud = true; args.cloud = true;
} }
#endif
if (arguments->abort) { if (arguments->abort) {
#ifndef _ALPINE #ifndef _ALPINE
......
...@@ -37,9 +37,11 @@ void *cancelHandler(void *arg) { ...@@ -37,9 +37,11 @@ void *cancelHandler(void *arg) {
taosMsleep(10); taosMsleep(10);
continue; continue;
} }
#ifdef WEBSOCKET
if (args.restful || args.cloud) { if (args.restful || args.cloud) {
stop_fetch = true; stop_fetch = true;
} }
#endif
#ifdef LINUX #ifdef LINUX
int64_t rid = atomic_val_compare_exchange_64(&result, result, 0); int64_t rid = atomic_val_compare_exchange_64(&result, result, 0);
SSqlObj* pSql = taosAcquireRef(tscObjRef, rid); SSqlObj* pSql = taosAcquireRef(tscObjRef, rid);
...@@ -81,7 +83,6 @@ SShellArguments args = {.host = NULL, ...@@ -81,7 +83,6 @@ SShellArguments args = {.host = NULL,
.user = NULL, .user = NULL,
.database = NULL, .database = NULL,
.timezone = NULL, .timezone = NULL,
.restful = false,
.is_raw_time = false, .is_raw_time = false,
.is_use_passwd = false, .is_use_passwd = false,
.dump_config = false, .dump_config = false,
...@@ -93,9 +94,12 @@ SShellArguments args = {.host = NULL, ...@@ -93,9 +94,12 @@ SShellArguments args = {.host = NULL,
.pktNum = 100, .pktNum = 100,
.pktType = "TCP", .pktType = "TCP",
.netTestRole = NULL, .netTestRole = NULL,
#ifdef WEBSOCKET
.restful = false,
.cloud = true, .cloud = true,
.dsn = NULL, .dsn = NULL,
.timeout = 10, .timeout = 10,
#endif
}; };
/* /*
...@@ -135,6 +139,7 @@ int main(int argc, char* argv[]) { ...@@ -135,6 +139,7 @@ int main(int argc, char* argv[]) {
exit(0); exit(0);
} }
#ifdef WEBSOCKET
if (args.restful) { if (args.restful) {
args.dsn = calloc(1, 1024); args.dsn = calloc(1, 1024);
...@@ -148,6 +153,7 @@ int main(int argc, char* argv[]) { ...@@ -148,6 +153,7 @@ int main(int argc, char* argv[]) {
snprintf(args.dsn, 1024, "ws://%s:%d/rest/ws",args.host, args.port); snprintf(args.dsn, 1024, "ws://%s:%d/rest/ws",args.host, args.port);
} }
#endif
/* Initialize the shell */ /* Initialize the shell */
shellInit(&args); shellInit(&args);
......
...@@ -62,12 +62,14 @@ void printHelp() { ...@@ -62,12 +62,14 @@ void printHelp() {
printf("%s%s%s\n", indent, indent, "Packet length used for net test, default is 1000 bytes."); printf("%s%s%s\n", indent, indent, "Packet length used for net test, default is 1000 bytes.");
printf("%s%s\n", indent, "-N"); printf("%s%s\n", indent, "-N");
printf("%s%s%s\n", indent, indent, "Packet numbers used for net test, default is 100."); printf("%s%s%s\n", indent, indent, "Packet numbers used for net test, default is 100.");
#ifdef WEBSOCKET
printf("%s%s\n", indent, "-R"); printf("%s%s\n", indent, "-R");
printf("%s%s%s\n", indent, indent, "Connect and interact with TDengine use restful."); printf("%s%s%s\n", indent, indent, "Connect and interact with TDengine use restful.");
printf("%s%s\n", indent, "-E"); printf("%s%s\n", indent, "-E");
printf("%s%s%s\n", indent, indent, "The DSN to use when connecting TDengine's cloud services."); printf("%s%s%s\n", indent, indent, "The DSN to use when connecting TDengine's cloud services.");
printf("%s%s\n", indent, "-t"); printf("%s%s\n", indent, "-t");
printf("%s%s%s\n", indent, indent, "The timeout seconds for websocekt to interact."); printf("%s%s%s\n", indent, indent, "The timeout seconds for websocekt to interact.");
#endif
printf("%s%s\n", indent, "-S"); printf("%s%s\n", indent, "-S");
printf("%s%s%s\n", indent, indent, "Packet type used for net test, default is TCP."); printf("%s%s%s\n", indent, indent, "Packet type used for net test, default is TCP.");
printf("%s%s\n", indent, "-V"); printf("%s%s\n", indent, "-V");
...@@ -82,7 +84,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -82,7 +84,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
// for host // for host
if (strcmp(argv[i], "-h") == 0) { if (strcmp(argv[i], "-h") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
#ifdef WEBSOCKET
arguments->cloud = false; arguments->cloud = false;
#endif
arguments->host = argv[++i]; arguments->host = argv[++i];
} else { } else {
fprintf(stderr, "option -h requires an argument\n"); fprintf(stderr, "option -h requires an argument\n");
...@@ -114,7 +118,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -114,7 +118,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
// for management port // for management port
else if (strcmp(argv[i], "-P") == 0) { else if (strcmp(argv[i], "-P") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
#ifdef WEBSOCKET
arguments->cloud = false; arguments->cloud = false;
#endif
arguments->port = atoi(argv[++i]); arguments->port = atoi(argv[++i]);
} else { } else {
fprintf(stderr, "option -P requires an argument\n"); fprintf(stderr, "option -P requires an argument\n");
...@@ -138,7 +144,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -138,7 +144,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
} }
} else if (strcmp(argv[i], "-c") == 0) { } else if (strcmp(argv[i], "-c") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
#ifdef WEBSOCKET
arguments->cloud = false; arguments->cloud = false;
#endif
char *tmp = argv[++i]; char *tmp = argv[++i];
if (strlen(tmp) >= TSDB_FILENAME_LEN) { if (strlen(tmp) >= TSDB_FILENAME_LEN) {
fprintf(stderr, "config file path: %s overflow max len %d\n", tmp, TSDB_FILENAME_LEN - 1); fprintf(stderr, "config file path: %s overflow max len %d\n", tmp, TSDB_FILENAME_LEN - 1);
...@@ -220,6 +228,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -220,6 +228,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
#ifdef WEBSOCKET
else if (strcmp(argv[i], "-R") == 0) { else if (strcmp(argv[i], "-R") == 0) {
arguments->cloud = false; arguments->cloud = false;
...@@ -243,6 +252,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -243,6 +252,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
#endif
else if (strcmp(argv[i], "-V") == 0) { else if (strcmp(argv[i], "-V") == 0) {
printVersion(); printVersion();
...@@ -258,6 +268,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -258,6 +268,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
#ifdef WEBSOCKET
if (args.dsn == NULL) { if (args.dsn == NULL) {
if (args.cloud) { if (args.cloud) {
args.dsn = getenv("TDENGINE_CLOUD_DSN"); args.dsn = getenv("TDENGINE_CLOUD_DSN");
...@@ -274,6 +285,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -274,6 +285,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
} else { } else {
args.cloud = true; args.cloud = true;
} }
#endif
} }
void shellPrintContinuePrompt() { printf("%s", CONTINUE_PROMPT); } void shellPrintContinuePrompt() { printf("%s", CONTINUE_PROMPT); }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册