vtkSocketCommunicator byteswapping on re-connection
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
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 a subsequent 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 condition 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; // NEW!
}
}
Many thanks for all your help,