[vtkusers] vtkSocketCommunicator Bug+Patch

Luke J West ljw at noc.soton.ac.uk
Thu May 26 10:20:46 EDT 2005


When using vtkSocketCommunicator between architectures of differing  
endian-ness, vtkSocketCommunicator correctly calculates the  
SwapBytesInReceivedData flag. But only first time around.  
    
If ->CloseConnection() is invoked, and second connection established with 
->ConnectTo() or ->WaitForConnection(), there exists an intermittent 
byteswapping bug, and the reason is as follows...   
    
The penultimate statement of ->ConnectTo() is...   
    
   if ( serverIsBE != IAmBE )   
     {   
     this->SwapBytesInReceivedData = 1;   
     }   
    
Note that this->SwapBytesInReceivedData is undefined if the condiction is 
unmet! Similarly, the penultimate statement in ->WaitForConnection() is...   
    
     if ( clientIsBE != IAmBE )   
       {   
       this->SwapBytesInReceivedData = 1;   
       }   
     }   
    
Again, this will not reset the flag when the condition is unmet, and  
subsequent receive calls may swap bytes erroneously, depending on the value of 
->SwapBytesInReceivedData during the previous connected state.   
    
One patch would be to append something like...   
    
     else   
     {   
     this->SwapBytesInReceivedData = 0;   
     }   
          
to both of the above conditions in each of the two Connect methods, and 
another solution would be to insert something like...   
    
     this->SwapBytesInReceivedData = 0;   
    
in the ->CloseConnection() method.   
    
    
As always, arguments exist for adopting either (or indeed both) solutions, but 
in keeping with the style and treatment of the other state variables in the 
class (->Socket, and ->IsConnected, in particular), I would suggest the 
latter.   
    
    
So for clarity...   
    
I suggest inserting a single line to the ->CloseConnection() method in file  
vtkSocketCommunicator.cxx so the definition reads as follows...   
    
 void vtkSocketCommunicator::CloseConnection()   
 {   
   if ( this->IsConnected )   
     {   
     vtkCloseSocketMacro(this->Socket);   
     this->Socket = -1;   
     this->IsConnected = 0;   
     this->SwapBytesInReceivedData = 0;   
     }   
 }   
    
    
Many thanks for all your help,  
  
  
Luke J West  :  e-Science  Research Assistant  
---------------------------------------------  
Room 566/12, School of Ocean & Earth Sciences  
Southampton Oceanography Centre,  Southampton  
SO14 3ZH  United Kingdom  
---------------------------------------------  
Tel: +44 23 8059 4801   Fax: +44 23 8059 3052  
Mob: +44 79 6107 4783 Skype: ljwest  
---------------------------------------------  
http://godiva.soc.soton.ac.uk/  

-----------------------------------------------------------------------
National Oceanography Centre, Southampton :: http://www.noc.soton.ac.uk



More information about the vtkusers mailing list