[vtkusers] vtkSocketCommunicator Bug+Patch

Mathieu Malaterre mathieu.malaterre at kitware.com
Thu May 26 10:33:29 EDT 2005


Luke,

	That look like a bug to me. Could you register at: http://vtk.org/Bug. 
After you login you can add a bug for VTK.

Thanks for your report
Mathieu

Luke J West wrote:
> 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
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 




More information about the vtkusers mailing list