[vtk-developers] Suggest fix to vtkSocketCommunicator (SO_REUSEADDR)
Robert Belleman
robbel at science.uva.nl
Tue Jul 29 05:46:52 EDT 2003
Hi,
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 attached patch 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.
Thanks,
-- Rob
--
[] Robert Belleman, PhD X Faculty of Science, Informatics Inst. []
[] robbel at science.uva.nl |X| University of Amsterdam, the Netherlands []
[] tel: (+31) 20 525 7510 X http://www.science.uva.nl/~robbel/ []
-------------- next part --------------
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);
More information about the vtk-developers
mailing list