From e4235cc56031fda02663b9e638ed29613a47cfdd Mon Sep 17 00:00:00 2001 From: me_desk Date: Sun, 16 Sep 2012 20:47:33 +0000 Subject: close channel by client if it is not activated within PICA_CHAN_ACTIVATE_TIMEOUT seconds git-svn-id: svn://localhost/project_picapica/trunk@204 fb96df88-216d-11de-830c-f3023f12d8ac --- PICA_client.c | 19 ++++++++++++++++--- PICA_client.h | 5 +++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/PICA_client.c b/PICA_client.c index fb2353e..2675ae7 100755 --- a/PICA_client.c +++ b/PICA_client.c @@ -142,7 +142,9 @@ chnl->conn=ci; chnl->outgoing=is_outgoing; chnl->peer_id=uid; -chnl->sck_data = -1;//prevent closing stdin when closing not active connection +chnl->timestamp = time(0); + +chnl->sck_data = -1;//prevent closing stdin when closing non-active connection chnl->read_buf = calloc(PICA_CHANREADBUFSIZE, 1); @@ -932,7 +934,18 @@ while(ipt) nfds=ipt->sck_data; } + if (ipt->state != PICA_CHANSTATE_ACTIVE && (time(0) - ipt->timestamp) > PICA_CHAN_ACTIVATE_TIMEOUT) + { + kill_ptr = ipt; + } + ipt=ipt->next; + + if (kill_ptr) + { + PICA_close_channel(kill_ptr); + kill_ptr = 0; + } } //#warning "make sockets non-blocking!!!!" @@ -962,8 +975,8 @@ if (ret>0) } - ipt=ipt->next; - + ipt=ipt->next; + if (kill_ptr) { PICA_close_channel(kill_ptr); diff --git a/PICA_client.h b/PICA_client.h index 8d9299a..6ed4111 100755 --- a/PICA_client.h +++ b/PICA_client.h @@ -1,6 +1,8 @@ #ifndef PICA_CLIENT_H #define PICA_CLIENT_H +#include + #ifdef WIN32 #include @@ -75,6 +77,8 @@ typedef unsigned __int16 uint16_t; #define PICA_CONNSTATE_CONNECTING 17 #define PICA_CONNSTATE_CONNECTED 19 +#define PICA_CHAN_ACTIVATE_TIMEOUT 30 + struct PICA_conninfo; struct PICA_chaninfo; @@ -124,6 +128,7 @@ unsigned int write_buflen; struct PICA_chaninfo *next; struct PICA_chaninfo *prev; int state; +time_t timestamp; }; struct PICA_client_callbacks -- cgit v1.2.1