diff options
author | Jason Reiss <jreiss@multitech.com> | 2017-06-01 11:56:42 -0500 |
---|---|---|
committer | Jason Reiss <jreiss@multitech.com> | 2017-06-01 11:56:42 -0500 |
commit | 58c303129c5dde8c2e819cc248e237da4f7295f1 (patch) | |
tree | 9e0def3f73b304764ea6e69c46eced6d5b937e1f /main.cpp | |
parent | fec609b89aedcdace9ba5411206936ea7bf64d1a (diff) | |
download | lora-query-58c303129c5dde8c2e819cc248e237da4f7295f1.tar.gz lora-query-58c303129c5dde8c2e819cc248e237da4f7295f1.tar.bz2 lora-query-58c303129c5dde8c2e819cc248e237da4f7295f1.zip |
Revert to "node stats" command1.0.3
Change default timeout to 5 seconds for first read
after response is started set to 100 ms timeout to signal end of response
if timeout is provided use it for both timeouts
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -49,6 +49,7 @@ int opt_add_node = 0; int opt_delete_node = 0; int opt_update_node = 0; int opt_command = 0; +int opt_timeout = 0; char* command_command; char* node_get_addr; @@ -66,7 +67,7 @@ int timeout = TIMEOUT; const char* cmd_stats = "stats"; const char* cmd_stats_reset = "stats reset"; -const char* cmd_node_list = "node list"; +const char* cmd_node_list = "node stats"; const char* cmd_node_config = "node config"; const char* cmd_node_update = "node update"; const char* cmd_node_delete = "node delete"; @@ -215,8 +216,15 @@ void runCmd(const char *command) { char receiveMessage[MAX_RECEIVED_BYTES]; struct timeval tv; - tv.tv_sec = timeout / 1000; - tv.tv_usec = (timeout % 1000) * 1000; + + if (opt_timeout) { + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; + } else { + // set initial timeout to 5 seconds + tv.tv_sec = 5; + tv.tv_usec = 0; + } receiveStream.str(""); receiveStream.clear(); @@ -238,6 +246,10 @@ void runCmd(const char *command) { return; } + // Lower timeout for subsequent reads + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; + sendto(sockfd, command, strlen(command), 0, (struct sockaddr *) &servaddr, sizeof(servaddr)); while (1) { @@ -246,6 +258,13 @@ void runCmd(const char *command) { /*printf("timeout\n");*/ break; } + + // Lower timeout for subsequent reads + if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) { + printError("setsockopt error\n"); + return; + } + receiveStream << std::string(receiveMessage, receiveBytes); } } @@ -459,6 +478,7 @@ void parseOptions(int argc, char** argv) { break; } case 't': { + opt_timeout = 1; timeout = atoi(optarg); break; } |