From ca6cbf19ecdc5c9d5c5fb6cef3ae411cffc71589 Mon Sep 17 00:00:00 2001 From: fcolin Date: Mon, 13 Jun 2005 11:19:43 +0000 Subject: Ajout keepalive sur les sockets --- src/ivy.c | 5 ++--- src/ivysocket.c | 13 ++++++++++++- src/ivysocket.h | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ivy.c b/src/ivy.c index 303c737..ce9b2e8 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -309,8 +309,7 @@ static int MsgCall (const char *message, MsgSndPtr msg, Client client) } -static int -ClientCall (IvyClientPtr clnt, const char *message) +static int ClientCall (IvyClientPtr clnt, const char *message) { MsgSndPtr msg; int match_count = 0; @@ -555,6 +554,7 @@ static IvyClientPtr SendService( Client client ) IVY_LIST_ADD( clients, clnt ) if ( clnt ) { + SocketKeepAlive ( client, 1 ); clnt->msg_send = 0; clnt->client = client; clnt->app_name = strdup("Unknown"); @@ -610,7 +610,6 @@ static void *ClientCreate( Client client ) SocketGetRemoteHost( client, &remotehost, &remoteport ); printf("Connexion de %s:%hu\n", remotehost, remoteport ); #endif //DEBUG - return SendService (client); } diff --git a/src/ivysocket.c b/src/ivysocket.c index 50a4483..d777350 100644 --- a/src/ivysocket.c +++ b/src/ivysocket.c @@ -641,7 +641,18 @@ void SocketSendBroadcast (Client client, unsigned long host, unsigned short port perror ("*** send ***"); } va_end (ap ); } - +void SocketKeepAlive( Client client,int keepalive ) +{ + int alive = keepalive; + if (setsockopt(client->fd,SOL_SOCKET,SO_KEEPALIVE,(char*)&alive,sizeof(alive)) < 0) + { +#ifdef WIN32 + fprintf(stderr," setsockopt %d\n",WSAGetLastError()); +#endif + perror ("*** set socket option SO_KEEPALIVE ***"); + exit(0); + } +} /* Socket Multicast */ int SocketAddMember(Client client, unsigned long host ) diff --git a/src/ivysocket.h b/src/ivysocket.h index 312f6b9..b57a632 100644 --- a/src/ivysocket.h +++ b/src/ivysocket.h @@ -65,7 +65,7 @@ extern unsigned short SocketServerGetPort( Server server ); extern void SocketServerClose( Server server ); /* Client Part */ - +extern void SocketKeepAlive( Client client,int keepalive ); extern void SocketClose( Client client ); extern void SocketSend( Client client, char *fmt, ... ); extern void SocketSendRaw( Client client, char *buffer, int len ); -- cgit v1.1