summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2009-12-06 20:41:05 (GMT)
committerChristian Pointner <equinox@helsinki.at>2009-12-06 20:41:05 (GMT)
commit0e13f8198ac1edc6f9b3a62492425cbdfd8669e4 (patch)
tree72b0f072a3f35bf0f517645c36692a10842f5b6d
parent9d2bf892485205f92367aaec61e6ea9c7fb35c69 (diff)
added reconnect code to serialclient
-rw-r--r--heartbeatclient.c3
-rw-r--r--serialclient.c46
2 files changed, 27 insertions, 22 deletions
diff --git a/heartbeatclient.c b/heartbeatclient.c
index f02365e..26e198e 100644
--- a/heartbeatclient.c
+++ b/heartbeatclient.c
@@ -141,13 +141,12 @@ int main_loop(int serial_fd, int cmd_fd, options_t* opt)
time++;
if(time >= opt->timeout_) {
log_printf(WARNING, "timeout reached");
+ // call handler for timeout
time = 0;
}
continue;
}
- log_printf(WARNING, "select has data");
-
if(FD_ISSET(sig_fd, &tmpfds))
if(signal_handle())
return_value = 1;
diff --git a/serialclient.c b/serialclient.c
index fc09404..87e9428 100644
--- a/serialclient.c
+++ b/serialclient.c
@@ -228,28 +228,33 @@ int main(int argc, char* argv[])
fclose(pid_file);
}
- int cmd_fd = connect_command_socket(opt.command_sock_);
- if(cmd_fd < 0) {
- options_clear(&opt);
- log_close();
- exit(-1);
- }
-
+ int cmd_fd = 0;
int serial_fd = 0;
for(;;) {
- serial_fd = open(opt.serial_dev_, O_RDWR | O_NOCTTY);
- if(serial_fd < 0)
- ret = 2;
- else {
- ret = setup_tty(serial_fd, opt.baudrate_);
- if(ret)
+ cmd_fd = connect_command_socket(opt.command_sock_);
+ if(cmd_fd < 0)
+ ret = 3;
+ else {
+ serial_fd = open(opt.serial_dev_, O_RDWR | O_NOCTTY);
+ if(serial_fd < 0)
ret = 2;
- else
- ret = main_loop(serial_fd, cmd_fd, &opt);
- }
-
- if(ret == 2) {
- log_printf(ERROR, "%s error, trying to reopen in 5 seconds..", opt.serial_dev_);
+ else {
+ ret = setup_tty(serial_fd, opt.baudrate_);
+ if(ret)
+ ret = 2;
+ else
+ ret = main_loop(serial_fd, cmd_fd, &opt);
+ }
+ }
+
+ if(ret == 2 || ret == 3) {
+ if(ret == 2)
+ log_printf(ERROR, "%s error, trying to reopen in 5 seconds..", opt.serial_dev_);
+ if(ret == 3)
+ log_printf(ERROR, "socket error, trying to reconnect in 5 seconds..");
+
+ if(cmd_fd > 0)
+ close(cmd_fd);
if(serial_fd > 0)
close(serial_fd);
sleep(5);
@@ -258,7 +263,8 @@ int main(int argc, char* argv[])
break;
}
- close(cmd_fd);
+ if(cmd_fd > 0)
+ close(cmd_fd);
if(serial_fd > 0)
close(serial_fd);