diff options
| -rwxr-xr-x | PICA_node.c | 50 | ||||
| -rwxr-xr-x | PICA_node.h | 12 |
2 files changed, 58 insertions, 4 deletions
diff --git a/PICA_node.c b/PICA_node.c index e8b72a5..b823598 100755 --- a/PICA_node.c +++ b/PICA_node.c @@ -26,6 +26,9 @@ #define JOINSKYNET_TIMEOUT 15 #define SELECT_TIMEOUT 1 +#define NOREPLY_TIMEOUT 15 +#define KEEPALIVE_TIMEOUT 60 + clock_t TMO_CCLINK_WAITACTIVE=15;//CONF //таймаут ожидания перехода соединения в активное состояние char *my_addr;//TEMP CONF FIXME собственный ip-адрес узла, на котором он ожидает соединения @@ -325,6 +328,9 @@ if ((o = client_tree_search(callee_id))) { *((unsigned int*)mp->tail)=i->id; cclink_list_addlocal(i,o); + + o->tmst = time(0); + o->disconnect_ticking = 1;//if client does not reply in given time period, client is disconnected return 1; } @@ -358,6 +364,9 @@ PICA_debug1("received CONALLOW"); callee=(struct client *)ptr; caller_id=*(unsigned int*)(buf+2); +callee->disconnect_ticking = 0; +callee->tmst = time(0); + link=cclink_list_search(caller_id,callee->id); if (!link) @@ -384,6 +393,9 @@ PICA_debug1("received CONNDENY"); callee=(struct client *)ptr; caller_id=*(unsigned int*)(buf+2); +callee->disconnect_ticking = 0; +callee->tmst = time(0); + link=cclink_list_search(caller_id,callee->id); if (!link) @@ -1663,9 +1675,47 @@ while(il) } } +void process_timeouts_c2n() +{ +struct client *i_ptr, *kill_ptr; +int ret; + +i_ptr = client_list_head; +kill_ptr = 0; + +while(i_ptr) + { + if (i_ptr->disconnect_ticking) + { + clock_t cur_time = time(0); + + if (cur_time >= i_ptr->tmst) + { + if ((cur_time - i_ptr->tmst) > NOREPLY_TIMEOUT) + kill_ptr = i_ptr; + } + else + {//2038 year has come, and this code is still working somewhere with 32bit Unix timestamps :) + if ((i_ptr->tmst - cur_time ) > NOREPLY_TIMEOUT) + kill_ptr = i_ptr; + } + } + + i_ptr = i_ptr->next; + + if (kill_ptr) + { + PICA_info("Disconnecting user %u due to noreply timeout", kill_ptr -> id); + client_list_delete(kill_ptr); + kill_ptr=0; + } + } +} + int process_timeouts() { process_timeouts_newconn(); +process_timeouts_c2n(); process_timeouts_c2c(); //.. return 1; diff --git a/PICA_node.h b/PICA_node.h index 13de6b3..90521ec 100755 --- a/PICA_node.h +++ b/PICA_node.h @@ -94,8 +94,8 @@ int state; struct client* next;//структура client может быть одновременно в составе дерева и линейного списка struct client* prev; - - +time_t tmst; +int disconnect_ticking;//on sending message TO client this var is set to 1, on receiving some message FROM client this var is reset to 0 }; struct cclink //структура, описывающая соединение двух клиентов между собой через сервер @@ -103,7 +103,7 @@ struct cclink //структура, описывающая соединение //unsigned int cclink_id; unsigned int state; -clock_t tmst; +time_t tmst; struct client *p1;//caller struct client *p2;//callee @@ -126,13 +126,14 @@ unsigned int bufpos_p2p1; struct cclink *next; struct cclink *prev; +int disconnect_ticking; }; struct newconn //структура, описывающая новое подключение (клиента) { SOCKET sck; struct sockaddr_in addr; -clock_t tmst; +time_t tmst; int pos; unsigned char buf[NEWCONN_BUFSIZE]; }; @@ -155,6 +156,9 @@ unsigned int w_pos; struct nodelink *next; struct nodelink *prev; + +time_t tmst; +int disconnect_ticking; }; #endif |
