MantisBT - VTK
View Issue Details
0000148VTK(No Category)public2003-08-15 02:492011-01-13 17:00
Robert Belleman 
Berk Geveci 
urgentmajoralways
closedfixed 
 
 
0000148: vtkSocketCommunicator can not bind socket to address that is in use
I would like to suggest a small change that will allow vtkSocketCommunicator to bind() a socket to an address that is still (or already) in use.

While testing, it frequently happened to me that a call to vtkSocketCommunicator::WaitForConnection(int port) fails because sockets from a previous run are still in a final closing/wait state. During that time, a bind() by a new run will fail with a "address already in use" error.

The patch below fixes that by allowing the address to be reused.

This change has been tested on Linux. I checked Window's API docs and other manual pages; this change should work equally well on other systems.

Context diff follows:

--------------------------------------------------
Index: vtkSocketCommunicator.cxx
===================================================================
RCS file: /cvsroot/VTK/VTK/Parallel/vtkSocketCommunicator.cxx,v
retrieving revision 1.40
diff -c -r1.40 vtkSocketCommunicator.cxx
*** vtkSocketCommunicator.cxx 29 Apr 2003 17:15:37 -0000 1.40
--- vtkSocketCommunicator.cxx 29 Jul 2003 09:45:35 -0000
***************
*** 286,291 ****
--- 286,296 ----
    server.sin_family = AF_INET;
    server.sin_addr.s_addr = INADDR_ANY;
    server.sin_port = htons(port);
+
+ // Allow the socket to be bound to an address that is already in use
+ int opt=1;
+ setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &opt, sizeof(int));
+
    if ( bind(sock, (sockaddr *)&server, sizeof(server)) )
      {
      vtkErrorMacro("Can not bind socket to port " << port);
No tags attached.
Issue History
2007-08-28 14:58Zack GalbreathProject@8@ => VTK
2007-08-28 14:58Zack GalbreathAssigned ToWill Schroeder => Berk Geveci
2007-08-28 14:58Zack GalbreathStatusbacklog => closed
2007-08-28 14:58Zack GalbreathResolutionduplicate => fixed
2007-08-28 14:58Zack GalbreathSummaryGoodsite => vtkSocketCommunicator can not bind socket to address that is in use
2007-08-28 14:59Zack GalbreathNote Deleted: 0008215
2010-11-29 17:59Berk GeveciSource_changeset_attached => VTK master db58ff40
2011-01-13 17:00Source_changeset_attached => VTK master a2bd8391
2011-01-13 17:00Source_changeset_attached => VTK master 020ef709
2011-06-16 13:11Zack GalbreathCategory => (No Category)

Notes
(0000395)
Berk Geveci   
2003-12-23 10:48   
Fix now in ParaView trunk.