vtkSocketCommunicator can not bind socket to address that is in use
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
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);