fix: get default port rule

This commit is contained in:
Alex Duan 2025-03-21 13:11:46 +08:00
parent 28ff3f75ad
commit 309cd47aa3
8 changed files with 63 additions and 43 deletions

View File

@ -72,4 +72,10 @@ int8_t getConnMode(char *arg);
char* strToLowerCopy(const char *str);
int32_t parseDsn(char* dsn, char **host, char **port, char **user, char **pwd, char* error);
int32_t setConnMode(int8_t connMode, char *dsn);
uint16_t defaultPort(int8_t connMode, char *dsn);
int8_t defaultMode(int8_t connMode, char *dsn);
#endif // PUB_H_

View File

@ -21,6 +21,7 @@
#include "geosWrapper.h"
#include "shellAuto.h"
#include "shellInt.h"
#include "../../inc/pub.h"
SShellObj shell = {0};
@ -1347,7 +1348,7 @@ TAOS* createConnect(SShellArgs *pArgs) {
if (pArgs->port_inputted) {
port = pArgs->port;
} else {
port = pArgs->connMode == CONN_MODE_NATIVE ? DEFAULT_PORT_NATIVE : DEFAULT_PORT_WS_LOCAL;
port = defaultPort(pArgs->connMode, pArgs->dsn);
}
sprintf(show, "host:%s port:%d ", host, port);
@ -1364,7 +1365,7 @@ TAOS* createConnect(SShellArgs *pArgs) {
int32_t shellExecute(int argc, char *argv[]) {
int32_t code = 0;
printf(shell.info.clientVersion, shell.info.cusName,
shell.args.connMode == CONN_MODE_NATIVE ? STR_NATIVE : STR_WEBSOCKET,
defaultMode(shell.args.connMode, shell.args.dsn),
taos_get_client_info(), shell.info.cusName);
fflush(stdout);

View File

@ -54,23 +54,6 @@ void initArgument(SShellArgs *pArgs) {
pArgs->port_inputted = false;
}
// set conn mode
int32_t setConnMode(int8_t connMode) {
// default
if (connMode == CONN_MODE_INVALID) {
connMode = CONN_MODE_DEFAULT;
}
// set conn mode
char * strMode = connMode == CONN_MODE_NATIVE ? STR_NATIVE : STR_WEBSOCKET;
int32_t code = taos_options(TSDB_OPTION_DRIVER, strMode);
if (code != TSDB_CODE_SUCCESS) {
fprintf(stderr, "failed to load driver since %s [0x%08X]\r\n", taos_errstr(NULL), taos_errno(NULL));
return -1;
}
return 0;
}
int main(int argc, char *argv[]) {
#if !defined(WINDOWS)
taosSetSignal(SIGBUS, shellCrashHandler);
@ -118,7 +101,7 @@ int main(int argc, char *argv[]) {
return -1;
}
if (setConnMode(shell.args.connMode)) {
if (setConnMode(&shell.args.connMode, shell.args.dsn)) {
return -1;
}

View File

@ -11,6 +11,7 @@
*/
#include <stdio.h>
#include <taos.h>
#include "../inc/pub.h"
@ -88,4 +89,50 @@
exit(-1);
}
}
// set conn mode
int32_t setConnMode(int8_t connMode, char *dsn) {
// check default
if (connMode == CONN_MODE_INVALID) {
if (dsn && dsn[0] != 0) {
connMode = CONN_MODE_WEBSOCKET;
} else {
// default
connMode = CONN_MODE_DEFAULT;
}
}
// set conn mode
char * strMode = connMode == CONN_MODE_NATIVE ? STR_NATIVE : STR_WEBSOCKET;
int32_t code = taos_options(TSDB_OPTION_DRIVER, strMode);
if (code != TSDB_CODE_SUCCESS) {
fprintf(stderr, "failed to load driver. since %s [0x%08X]\r\n", taos_errstr(NULL), taos_errno(NULL));
return code;
}
return 0;
}
// default mode
int8_t defaultMode(int8_t connMode, char *dsn) {
int8_t mode = connMode;
if (connMode == CONN_MODE_INVALID) {
// no input from command line or config
if (dsn && dsn[0] != 0) {
mode = CONN_MODE_WEBSOCKET;
} else {
// default
mode = CONN_MODE_DEFAULT;
}
}
return mode;
}
// get default port
uint16_t defaultPort(int8_t connMode, char *dsn) {
// consistent with setConnMode
int8_t mode = defaultMode(connMode, dsn);
// default port
return mode == CONN_MODE_NATIVE ? DEFAULT_PORT_NATIVE : DEFAULT_PORT_WS_LOCAL;
}

View File

@ -109,7 +109,7 @@ int32_t setConnMode(int8_t connMode) {
int32_t code = taos_options(TSDB_OPTION_DRIVER, strMode);
if (code != TSDB_CODE_SUCCESS) {
engineError(INIT_PHASE, "taos_options", code);
return -1;
return code;
}
infoPrint("Connect mode is : %s\n\n", strMode);
@ -186,7 +186,7 @@ int main(int argc, char* argv[]) {
}
// conn mode
if (setConnMode(g_arguments->connMode) != 0) {
if (setConnMode(g_arguments->connMode, g_arguments->dsn) != 0) {
exitLog();
return -1;
}

View File

@ -13,6 +13,7 @@
#include <ctype.h>
#include <bench.h>
#include "benchLog.h"
#include "pub.h"
char resEncodingChunk[] = "Encoding: chunked";
char succMessage[] = "succ";
@ -304,7 +305,7 @@ SBenchConn* initBenchConnImpl() {
if (g_arguments->port_inputted) {
port = g_arguments->port;
} else {
port = g_arguments->connMode == CONN_MODE_NATIVE ? DEFAULT_PORT_NATIVE : DEFAULT_PORT_WS_LOCAL;
port = defaultPort(g_arguments->connMode, g_arguments->dsn);
}
sprintf(show, "host:%s port:%d ", host, port);

View File

@ -136,7 +136,7 @@ TAOS *taosConnect(const char *dbName) {
if (g_args.port_inputted) {
port = g_args.port;
} else {
port = g_args.connMode == CONN_MODE_NATIVE ? DEFAULT_PORT_NATIVE : DEFAULT_PORT_WS_LOCAL;
port = defaultPort(g_args.connMode, g_args.dsn);
}
sprintf(show, "host:%s port:%d ", host, port);

View File

@ -10856,24 +10856,6 @@ static int inspectAvroFiles(int argc, char *argv[]) {
return ret;
}
int32_t setConnMode(int8_t connMode) {
// default
if (connMode == CONN_MODE_INVALID) {
connMode = CONN_MODE_DEFAULT;
}
// set conn mode
char * strMode = connMode == CONN_MODE_NATIVE ? STR_NATIVE : STR_WEBSOCKET;
int32_t code = taos_options(TSDB_OPTION_DRIVER, strMode);
if (code != TSDB_CODE_SUCCESS) {
engineError(INIT_PHASE, "taos_options", code);
return -1;
}
infoPrint("\nConnect mode is : %s\n\n", strMode);
return 0;
}
int main(int argc, char *argv[]) {
g_uniqueID = getUniqueIDFromEpoch();
@ -10928,7 +10910,7 @@ int main(int argc, char *argv[]) {
}
// conn mode
if (setConnMode(g_args.connMode) != 0) {
if (setConnMode(g_args.connMode, g_args.dsn) != 0) {
return -1;
}