From 0003cad81aa18c00100ade38e97cdd7ad22aa2a2 Mon Sep 17 00:00:00 2001 From: qianfan Zhao Date: Tue, 6 Aug 2019 14:07:07 +0800 Subject: [PATCH] canlogserver: Close accsocket and can when tcp client disconnected Close all can socket and send "FYI" to tcp client when the tcp client disconnected. Signed-off-by: qianfan Zhao --- canlogserver.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/canlogserver.c b/canlogserver.c index 4429ccdb..b344df9d 100644 --- a/canlogserver.c +++ b/canlogserver.c @@ -151,7 +151,7 @@ int idx2dindex(int ifidx, int socket) return i; } -/* +/* * This is a Signalhandler. When we get a signal, that a child * terminated, we wait for it, so the zombie will disappear. */ @@ -303,7 +303,7 @@ int main(int argc, char **argv) exit(1); } } - + for (i=0; i 0) + close(s[i]); + goto close_accsocket; } if (mask[i] || value[i]) { @@ -371,17 +373,32 @@ int main(int argc, char **argv) while (running) { + int maxfd = accsocket; + FD_ZERO(&rdfs); - for (i=0; i maxfd ? s[i] : maxfd; FD_SET(s[i], &rdfs); + } - if ((ret = select(s[currmax-1]+1, &rdfs, NULL, NULL, NULL)) < 0) { + if ((ret = select(maxfd + 1, &rdfs, NULL, NULL, NULL)) < 0) { //perror("select"); running = 0; continue; } for (i=0; i