diff options
author | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2013-12-02 11:38:31 +0100 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2014-01-10 07:15:51 +0100 |
commit | 2b63b0ee2fc000d298faaf29b80cb840d43934d5 (patch) | |
tree | fa1754ba3ec156de218c3eaf0d26d632ecdb4df4 /src | |
parent | 55df0f3aa8500619464bd080f0d58d2419da0c4c (diff) | |
download | DLT-daemon-2b63b0ee2fc000d298faaf29b80cb840d43934d5.tar.gz |
Close socket when send fails.
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/dlt-daemon.c | 85 | ||||
-rwxr-xr-x | src/daemon/dlt-daemon.h | 2 | ||||
-rw-r--r-- | src/daemon/dlt_daemon_common.c | 6 |
3 files changed, 62 insertions, 31 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 87663c6..00ac525 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -1233,29 +1233,8 @@ int dlt_daemon_process_client_messages(DltDaemon *daemon, DltDaemonLocal *daemon if (dlt_receiver_receive_socket(&(daemon_local->receiverSock))<=0) { - close(daemon_local->receiverSock.fd); - FD_CLR(daemon_local->receiverSock.fd, &(daemon_local->master)); - daemon_local->receiverSock.fd = -1; - - if (daemon_local->client_connections) - { - daemon_local->client_connections--; - } - - if(daemon_local->client_connections==0) - { - /* send new log state to all applications */ - daemon->state = 0; - dlt_daemon_user_send_all_log_state(daemon,verbose); - } - - if (daemon_local->flags.vflag) - { - sprintf(str, "Connection to client lost, #connections: %d\n",daemon_local->client_connections); - dlt_log(LOG_INFO, str); - } - - dlt_daemon_control_message_connection_info(DLT_DAEMON_STORE_TO_BUFFER,daemon,DLT_CONNECTION_STATUS_DISCONNECTED,"",verbose); + dlt_daemon_close_socket(daemon_local->receiverSock.fd, daemon, daemon_local, verbose); + daemon_local->receiverSock.fd = -1; /* check: return 0; */ } @@ -2142,15 +2121,30 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo #endif && (j!=daemon_local->timer_timingpacket) && (j!=daemon_local->timer_ecuversion)) { + int failed = 0; + DLT_DAEMON_SEM_LOCK(); if (daemon_local->flags.lflag) { - send(j,dltSerialHeader,sizeof(dltSerialHeader),0); + if(0 > send(j,dltSerialHeader,sizeof(dltSerialHeader),0)) + { + dlt_daemon_close_socket(j, daemon, daemon_local, verbose); + failed = 1; + } } - send(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader),0); - send(j,daemon_local->msg.databuffer,daemon_local->msg.datasize,0); + if(!failed && 0 > send(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader),0)) + { + dlt_daemon_close_socket(j, daemon, daemon_local, verbose); + failed = 1; + } + + if(!failed && 0 > send(j,daemon_local->msg.databuffer,daemon_local->msg.datasize,0)) + { + dlt_daemon_close_socket(j, daemon, daemon_local, verbose); + failed = 1; + } DLT_DAEMON_SEM_FREE(); @@ -2563,13 +2557,22 @@ int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daem #endif && (j!=daemon_local->timer_timingpacket) && (j!=daemon_local->timer_ecuversion)) { + int failed = 0; DLT_DAEMON_SEM_LOCK(); if (daemon_local->flags.lflag) { - send(j,dltSerialHeader,sizeof(dltSerialHeader),0); + if(!failed && 0 > send(j,dltSerialHeader,sizeof(dltSerialHeader),0)) + { + dlt_daemon_close_socket(j, daemon, daemon_local, verbose); + failed = 1; + } + } + if(!failed && 0 > send(j,data,length,0)) + { + dlt_daemon_close_socket(j, daemon, daemon_local, verbose); + failed = 1; } - send(j,data,length,0); DLT_DAEMON_SEM_FREE(); @@ -2777,6 +2780,32 @@ void dlt_daemon_send_ecuversion(DltDaemon *daemon, DltDaemonLocal *daemon_local) } } +/* Close connection function */ +int dlt_daemon_close_socket(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +{ + close(sock); + FD_CLR(sock, &(daemon_local->master)); + + if (daemon_local->client_connections) + { + daemon_local->client_connections--; + } + + if(daemon_local->client_connections==0) + { + /* send new log state to all applications */ + daemon->state = 0; + dlt_daemon_user_send_all_log_state(daemon,verbose); + } + + if (daemon_local->flags.vflag) + { + sprintf(str, "Connection to client lost, #connections: %d\n",daemon_local->client_connections); + dlt_log(LOG_INFO, str); + } + + dlt_daemon_control_message_connection_info(DLT_DAEMON_STORE_TO_BUFFER,daemon,DLT_CONNECTION_STATUS_DISCONNECTED,"",verbose); +} /** \} */ diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h index 2e4f62c..46321a7 100755 --- a/src/daemon/dlt-daemon.h +++ b/src/daemon/dlt-daemon.h @@ -195,5 +195,7 @@ int create_timer_fd(DltDaemonLocal *daemon_local, int period_sec, int starts_in, void dlt_daemon_send_timingpacket(DltDaemon *daemon, DltDaemonLocal *daemon_local);
void dlt_daemon_send_ecuversion(DltDaemon *daemon, DltDaemonLocal *daemon_local);
+int dlt_daemon_close_socket(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
+
#endif /* DLT_DAEMON_H */
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c index 7a344db..d47aafa 100644 --- a/src/daemon/dlt_daemon_common.c +++ b/src/daemon/dlt_daemon_common.c @@ -2538,18 +2538,18 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, int verbose) /* Optional: Send serial header, if requested */ if (daemon->sendserialheader) { - if ( -1 == send(sock, dltSerialHeader,sizeof(dltSerialHeader),0) ) + if ( 0 > send(sock, dltSerialHeader,sizeof(dltSerialHeader),0) ) dlt_log(LOG_ERR,"dlt_daemon_control_message_time: Failed to send dltSerialHeader"); } /* Send data */ - if (-1 == send(sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader),0)) + if (0 > send(sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader),0)) dlt_log(LOG_ERR,"dlt_daemon_control_message_time: Failed to send DltStorageHeader"); if(msg.datasize > 0) { - if (-1 == send(sock, msg.databuffer,msg.datasize,0) ) + if (0 > send(sock, msg.databuffer,msg.datasize,0) ) dlt_log(LOG_ERR,"dlt_daemon_control_message_time: Failed to send databuffer"); } |