From 51b8c0cb530de874de351d6a7d954c21a7644a3e Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Tue, 16 Mar 2010 13:55:45 +0000 Subject: [PATCH] usocket honor EOF --- serial_console/usocket.c | 41 +++++++++++++++++------------------------ serial_console/usocket.h | 2 +- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/serial_console/usocket.c b/serial_console/usocket.c index 7008090..d00a8b5 100644 --- a/serial_console/usocket.c +++ b/serial_console/usocket.c @@ -64,7 +64,7 @@ void connect_terminal(int fd) { send(fd,buffer,num_byte,0); } - if (num_byte <0 && errno != EAGAIN) + if (num_byte == 0 || (num_byte <0 && errno != EAGAIN)) return; } @@ -109,30 +109,23 @@ int main(int argc, char* argv[]) if (argc > 0) socket_file_ = argv[1]; - for(;;) + socket_fd = establish_socket_connection(socket_file_); + if(socket_fd) { - socket_fd = establish_socket_connection(socket_file_); - if(socket_fd < 0) - ret = 2; - else { - //~ ret = set_tty_raw(STDIN_FILENO,&tmio_prev); - //~ if (ret) - //~ break; - fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); - connect_terminal(socket_fd); - - //~ ret = restore_tty(STDIN_FILENO,&tmio_prev); - //~ if (ret) - //~ break; - } - if (ret == 2) { - fprintf(stderr, "%s error, trying to reopen in 5 seconds..\n", socket_file_); - if(socket_fd > 0) - shutdown(socket_fd,SHUT_RDWR); - sleep(5); - } - else - break; + //~ ret = set_tty_raw(STDIN_FILENO,&tmio_prev); + //~ if (ret) + //~ break; + fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); + connect_terminal(socket_fd); + + //~ ret = restore_tty(STDIN_FILENO,&tmio_prev); + //~ if (ret) + //~ break; + } + else + { + fprintf(stderr, "%s error, aborting..\n", socket_file_); + ret=2; } if(socket_fd > 0) diff --git a/serial_console/usocket.h b/serial_console/usocket.h index 3bb470a..cc458c4 100644 --- a/serial_console/usocket.h +++ b/serial_console/usocket.h @@ -10,5 +10,5 @@ #include #include -char const *socket_file_="/var/run/sensor.socket"; +char const *socket_file_="/var/run/powersensordaemon/cmd.sock"; -- 1.7.10.4