certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] certi/libCERTI SocketTCP.hh SocketTCP.cc


From: certi-cvs
Subject: [certi-cvs] certi/libCERTI SocketTCP.hh SocketTCP.cc
Date: Mon, 05 May 2008 09:06:52 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Eric NOULARD <erk>      08/05/05 09:06:52

Modified files:
        libCERTI       : SocketTCP.hh SocketTCP.cc 

Log message:
        Fix bug #23151 : Annoying "address already in use" error
        A patch from Petr Gotthard

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketTCP.hh?cvsroot=certi&r1=3.19&r2=3.20
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketTCP.cc?cvsroot=certi&r1=3.22&r2=3.23

Patches:
Index: SocketTCP.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/SocketTCP.hh,v
retrieving revision 3.19
retrieving revision 3.20
diff -u -b -r3.19 -r3.20
--- SocketTCP.hh        9 Dec 2007 16:46:50 -0000       3.19
+++ SocketTCP.hh        5 May 2008 09:06:52 -0000       3.20
@@ -81,7 +81,6 @@
        int connect(in_port_t port, in_addr_t addr);
        int listen(unsigned long howMuch=5);
        int bind(in_port_t port=0, in_addr_t addr=INADDR_ANY);
-       void changeReuseOption();
        void setPort(in_port_t port);
        in_port_t getPort() const ;
        in_addr_t getAddr() const ;

Index: SocketTCP.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/SocketTCP.cc,v
retrieving revision 3.22
retrieving revision 3.23
diff -u -b -r3.22 -r3.23
--- SocketTCP.cc        3 Apr 2008 15:21:52 -0000       3.22
+++ SocketTCP.cc        5 May 2008 09:06:52 -0000       3.23
@@ -17,7 +17,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: SocketTCP.cc,v 3.22 2008/04/03 15:21:52 rousse Exp $
+// $Id: SocketTCP.cc,v 3.23 2008/05/05 09:06:52 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifdef _WIN32
@@ -241,47 +241,21 @@
 
 Length = sizeof(_sockIn);
 
-Result = ::bind(_socket_tcp, (sockaddr *)&_sockIn, Length);
+    int on = 1 ;
+    /* Bind even if the port is in the TIME_WAIT. If the port is busy,
+     * An error will be reported if the port is busy with another state. */
+    if (setsockopt(_socket_tcp,
+        SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)))
+       perror("setsockopt");
 
-#ifdef _WIN32
-       if((Result <0) &&(WSAGetLastError() == WSAEADDRINUSE))
-#else
-       if((Result <0) &&(errno == EADDRINUSE))
-#endif
-       {// Error on Bind. If the error is "Address already in use", allow
-       // the user to choose to "reuse address" and then try again.
-       changeReuseOption();
        Result = ::bind(_socket_tcp, (sockaddr *)&_sockIn, Length);
-       }
-
-if (Result == 0)
-       return 1 ;
-else
-       return 0 ;
-}
 
-// ----------------------------------------------------------------------------
-void
-SocketTCP::changeReuseOption()
-{
-int on = 1 ;
-
-cout << endl << "TCP Server, Bind : Address already in use." << endl ;
-cout << "If you are sure no other RTIG is running, we can try to set" << endl ;
-cout << "the \"Reuse Address\" option and try again." << endl ;
-cout << "\tPress ENTER to try again or CTRL-C to abort." << endl ;
-
-fflush(stdin); getchar();
-
-// Set the SO_REUSEADDR option(Server Side)
-if (setsockopt(_socket_tcp,
-                                       SOL_SOCKET,
-                                       SO_REUSEADDR,
-                                       (char *)&on,
-                                       sizeof(on))) 
-       {
-       perror("Setsockopt");
+    if (Result != 0) {
+        perror("bind");
+       return 0;
        }
+    else
+        return 1;
 }
 
 // ----------------------------------------------------------------------------
@@ -621,4 +595,4 @@
 
 } // namespace
 
-// $Id: SocketTCP.cc,v 3.22 2008/04/03 15:21:52 rousse Exp $
+// $Id: SocketTCP.cc,v 3.23 2008/05/05 09:06:52 erk Exp $




reply via email to

[Prev in Thread] Current Thread [Next in Thread]