From e0c708eceba3e8cd9e09c25a463313f966fbfafb Mon Sep 17 00:00:00 2001 From: Stefan Krulj Date: Tue, 11 Nov 2014 03:36:12 +0100 Subject: [PATCH] Server now checks the connection and correctly closes the clients file descriptor if the client exits silently --- src/DAP_config.h | 2 +- src/socket_ipc.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/DAP_config.h b/src/DAP_config.h index e108a76..89e856f 100644 --- a/src/DAP_config.h +++ b/src/DAP_config.h @@ -86,7 +86,7 @@ Provides definitions about: /// This configuration settings is used to optimized the communication performance with the /// debugger and depends on the USB peripheral. For devices with limited RAM or USB buffer the /// setting can be reduced (valid range is 1 .. 255). Change setting to 4 for High-Speed USB. -#define DAP_PACKET_COUNT 64 ///< Buffers: 64 = Full-Speed, 4 = High-Speed. +#define DAP_PACKET_COUNT 1 ///< Buffers: 64 = Full-Speed, 4 = High-Speed. /// Debug Unit is connected to fixed Target Device. diff --git a/src/socket_ipc.c b/src/socket_ipc.c index 3bfcab2..39cce31 100644 --- a/src/socket_ipc.c +++ b/src/socket_ipc.c @@ -108,6 +108,7 @@ void wait_for_client(void) { if(flags < 0 ){ flags = 0; } + /* TODO change nonblocking to a timed out read */ if( fcntl(csockfd, F_SETFL, flags | O_NONBLOCK) < 0 ){ DEBUGF("ERROR seting non-blocking: %s\n", strerror(errno)); } @@ -178,7 +179,13 @@ void process_data(void) { } }else if( n<0 ){ switch( errno ) { - case EAGAIN: break; + case EAGAIN: + /* try to write an empty message to check connection */ + n = write(csockfd,NULL,0); + if( n == 0 ){ + break; + } + /*no break*/ default: DEBUGF("A problem occured: %d %d %s\n", n, errno,strerror(errno) ); DEBUG("Closing connection!\n");