diff --git a/darkice/trunk/ChangeLog b/darkice/trunk/ChangeLog index a305087..b01b29f 100644 --- a/darkice/trunk/ChangeLog +++ b/darkice/trunk/ChangeLog @@ -1,5 +1,7 @@ DarkIce next release + o improvements on reconnecting: + added TCP connection keep-alive to TCP sockets o added user-defined date formatting for the fileAddDate options, thanks to dsk o added logging facility - [file-X] targets will cut the saved file diff --git a/darkice/trunk/src/TcpSocket.cpp b/darkice/trunk/src/TcpSocket.cpp index c89ae2e..b55ca57 100644 --- a/darkice/trunk/src/TcpSocket.cpp +++ b/darkice/trunk/src/TcpSocket.cpp @@ -192,6 +192,8 @@ TcpSocket :: operator= ( const TcpSocket & ss ) throw ( Exception ) bool TcpSocket :: open ( void ) throw ( Exception ) { + int optval; + socklen_t optlen; #ifdef HAVE_ADDRINFO struct addrinfo hints struct addrinfo * ptr; @@ -213,7 +215,7 @@ TcpSocket :: open ( void ) throw ( Exception ) snprintf(portstr, sizeof(portstr), "%d", port); if (getaddrinfo(host , portstr, &hints, &ptr)) { - throw Exception( __FILE__, __LINE__, "getaddrinfo error", errno); + throw Exception( __FILE__, __LINE__, "getaddrinfo error", errno); } memcpy ( addr, ptr->ai_addr, ptr->ai_addrlen); freeaddrinfo(ptr); @@ -222,15 +224,24 @@ TcpSocket :: open ( void ) throw ( Exception ) throw Exception( __FILE__, __LINE__, "gethostbyname error", errno); } - if ( (sockfd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1 ) { - throw Exception( __FILE__, __LINE__, "socket error", errno); - } - memset( &addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = *((long*) pHostEntry->h_addr_list[0]); #endif + + if ( (sockfd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1 ) { + throw Exception( __FILE__, __LINE__, "socket error", errno); + } + + // set TCP keep-alive + optval = 1; + optlen = sizeof(optval); + if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) == -1) { + reportEvent(5, "can't set TCP socket keep-alive mode", errno); + } + + // connect if ( connect( sockfd, (struct sockaddr*)&addr, sizeof(addr)) == -1 ) { ::close( sockfd); sockfd = 0; diff --git a/darkice/trunk/src/TcpSocket.h b/darkice/trunk/src/TcpSocket.h index f37a2fb..789ef52 100644 --- a/darkice/trunk/src/TcpSocket.h +++ b/darkice/trunk/src/TcpSocket.h @@ -38,6 +38,7 @@ #include "Source.h" #include "Sink.h" +#include "Reporter.h" /* ================================================================ constants */ @@ -54,7 +55,7 @@ * @author $Author$ * @version $Revision$ */ -class TcpSocket : public Source, public Sink +class TcpSocket : public Source, public Sink, public virtual Reporter { private: