summaryrefslogtreecommitdiff
path: root/serialclient.c
diff options
context:
space:
mode:
Diffstat (limited to 'serialclient.c')
-rw-r--r--serialclient.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/serialclient.c b/serialclient.c
index f374774..a32c691 100644
--- a/serialclient.c
+++ b/serialclient.c
@@ -47,6 +47,8 @@ int process_data(int src_fd, int dest_fd)
return 0;
if(ret < 0)
return ret;
+
+ log_printf(DEBUG, "read %d bytes from fd (%d)", ret, src_fd);
int len = ret;
int offset = 0;
@@ -63,7 +65,7 @@ int process_data(int src_fd, int dest_fd)
if(offset+1 >= len)
break;
}
- return ret;
+ return 0;
}
int main_loop(int serial_fd, int cmd_fd, options_t* opt)
@@ -83,8 +85,26 @@ int main_loop(int serial_fd, int cmd_fd, options_t* opt)
max_fd = (max_fd < sig_fd) ? sig_fd : max_fd;
int return_value = 0;
-
- return_value = send_string(cmd_fd, opt->type_);
+ if(opt->type_) {
+ char* tmp;
+ asprintf(&tmp, "type %s\n", opt->type_);
+ if(!tmp) {
+ log_printf(ERROR, "memory error at init");
+ return_value = -2;
+ }
+ else {
+ return_value = send_string(cmd_fd, tmp);
+ free(tmp);
+ if(return_value <= 0) {
+ log_printf(ERROR, "error setting client type");
+ return_value = -1;
+ }
+ else {
+ log_printf(NOTICE, "connecting as type '%s'", opt->type_);
+ return_value = 0;
+ }
+ }
+ }
while(!return_value) {
memcpy(&tmpfds, &readfds, sizeof(tmpfds));
@@ -98,22 +118,15 @@ int main_loop(int serial_fd, int cmd_fd, options_t* opt)
if(ret == -1 || !ret)
continue;
- if(FD_ISSET(sig_fd, &tmpfds)) {
- if(signal_handle()) {
+ if(FD_ISSET(sig_fd, &tmpfds))
+ if(signal_handle())
return_value = 1;
- break;
- }
- }
- if(FD_ISSET(serial_fd, &tmpfds)) {
+ if(FD_ISSET(serial_fd, &tmpfds))
return_value = process_data(serial_fd, cmd_fd);
- if(return_value)
- break;
- }
- if(FD_ISSET(cmd_fd, &tmpfds)) {
+ if(FD_ISSET(cmd_fd, &tmpfds))
return_value = process_data(cmd_fd, serial_fd);
- }
}
signal_stop();