View Revisions: Issue #4167

Summary 0004167: The OpenIGTLink SetSendBlocking code is duplicated from SetReceiveBlocking
Revision 2017-08-14 09:34 by jcfr
Additional Information

//-----------------------------------------------------------------------------
int Socket::SetReceiveBlocking(int sw)
{
if (!this->GetConnected())
{
return 0;
}

// If sw == 1, timeout is set to 0 (wait until it receives message)
#if defined(_WIN32) && !defined(CYGWIN)
if (sw==0)
{
this->m_ReceiveTimeout = 1;
}
else
{
this->m_ReceiveTimeout = 0;
}
int len;
#else
if (sw==0)
{
this->m_ReceiveTimeout.tv_sec = 0; / second /
this->m_ReceiveTimeout.tv_usec = 1; / nanosecond /
}
else
{
this->m_ReceiveTimeout.tv_sec = 0; / second /
this->m_ReceiveTimeout.tv_usec = 0; / nanosecond /
}
socklen_t len;
#endif
if (sw==0)
{
getsockopt(this->m_SocketDescriptor, SOL_SOCKET, SO_RCVTIMEO,
(char)&(this->m_OrigReceiveTimeout), &len);
setsockopt(this->m_SocketDescriptor, SOL_SOCKET, SO_RCVTIMEO,
(char
)&(this->m_ReceiveTimeout), sizeof(this->m_ReceiveTimeout));
this->m_ReceiveTimeoutFlag = 1;
}
else if (this->m_ReceiveTimeoutFlag)
{
setsockopt(this->m_SocketDescriptor, SOL_SOCKET, SO_RCVTIMEO,
(char*)&(this->m_OrigReceiveTimeout), sizeof(this->m_OrigReceiveTimeout));
this->m_ReceiveTimeoutFlag = 0;
}

return sw;
}

//-----------------------------------------------------------------------------
int Socket::SetSendBlocking(int sw)
{
if (!this->GetConnected())
{
return 0;
}

// If sw == 1, timeout is set to 0 (wait until it receives message)
#if defined(_WIN32) && !defined(CYGWIN)
if (sw==0)
{
this->m_ReceiveTimeout = 1;
}
else
{
this->m_ReceiveTimeout = 0;
}
int len;
#else
if (sw==0)
{
this->m_ReceiveTimeout.tv_sec = 0; / second /
this->m_ReceiveTimeout.tv_usec = 1; / nanosecond /
}
else
{
this->m_ReceiveTimeout.tv_sec = 0; / second /
this->m_ReceiveTimeout.tv_usec = 0; / nanosecond /
}
socklen_t len;
#endif
if (sw==0)
{
getsockopt(this->m_SocketDescriptor, SOL_SOCKET, SO_SNDTIMEO,
(char)&(this->m_OrigSendTimeout), &len);
setsockopt(this->m_SocketDescriptor, SOL_SOCKET, SO_SNDTIMEO,
(char
)&(this->m_SendTimeout), sizeof(this->m_SendTimeout));
this->m_SendTimeoutFlag = 1;
}
else if (this->m_SendTimeoutFlag)
{
setsockopt(this->m_SocketDescriptor, SOL_SOCKET, SO_SNDTIMEO,
(char*)&(this->m_OrigSendTimeout), sizeof(this->m_OrigSendTimeout));
this->m_SendTimeoutFlag = 0;
}

return sw;
}

Revision 2016-04-07 10:50 by leochan2009
Additional Information

//-----------------------------------------------------------------------------
int Socket::SetReceiveBlocking(int sw)
{
if (!this->GetConnected())
{
return 0;
}

// If sw == 1, timeout is set to 0 (wait until it receives message)
#if defined(_WIN32) && !defined(CYGWIN)
if (sw==0)
{
this->m_ReceiveTimeout = 1;
}
else
{
this->m_ReceiveTimeout = 0;
}
int len;
#else
if (sw==0)
{
this->m_ReceiveTimeout.tv_sec = 0; / second /
this->m_ReceiveTimeout.tv_usec = 1; / nanosecond /
}
else
{
this->m_ReceiveTimeout.tv_sec = 0; / second /
this->m_ReceiveTimeout.tv_usec = 0; / nanosecond /
}
socklen_t len;
#endif
if (sw==0)
{
getsockopt(this->m_SocketDescriptor, SOL_SOCKET, SO_RCVTIMEO,
(char)&(this->m_OrigReceiveTimeout), &len);
setsockopt(this->m_SocketDescriptor, SOL_SOCKET, SO_RCVTIMEO,
(char
)&(this->m_ReceiveTimeout), sizeof(this->m_ReceiveTimeout));
this->m_ReceiveTimeoutFlag = 1;
}
else if (this->m_ReceiveTimeoutFlag)
{
setsockopt(this->m_SocketDescriptor, SOL_SOCKET, SO_RCVTIMEO,
(char*)&(this->m_OrigReceiveTimeout), sizeof(this->m_OrigReceiveTimeout));
this->m_ReceiveTimeoutFlag = 0;
}

return sw;
}

//-----------------------------------------------------------------------------
int Socket::SetSendBlocking(int sw)
{
if (!this->GetConnected())
{
return 0;
}

// If sw == 1, timeout is set to 0 (wait until it receives message)
#if defined(_WIN32) && !defined(CYGWIN)
if (sw==0)
{
this->m_ReceiveTimeout = 1;
}
else
{
this->m_ReceiveTimeout = 0;
}
int len;
#else
if (sw==0)
{
this->m_ReceiveTimeout.tv_sec = 0; / second /
this->m_ReceiveTimeout.tv_usec = 1; / nanosecond /
}
else
{
this->m_ReceiveTimeout.tv_sec = 0; / second /
this->m_ReceiveTimeout.tv_usec = 0; / nanosecond /
}
socklen_t len;
#endif
if (sw==0)
{
getsockopt(this->m_SocketDescriptor, SOL_SOCKET, SO_SNDTIMEO,
(char)&(this->m_OrigSendTimeout), &len);
setsockopt(this->m_SocketDescriptor, SOL_SOCKET, SO_SNDTIMEO,
(char
)&(this->m_SendTimeout), sizeof(this->m_SendTimeout));
this->m_SendTimeoutFlag = 1;
}
else if (this->m_SendTimeoutFlag)
{
setsockopt(this->m_SocketDescriptor, SOL_SOCKET, SO_SNDTIMEO,
(char*)&(this->m_OrigSendTimeout), sizeof(this->m_OrigSendTimeout));
this->m_SendTimeoutFlag = 0;
}

return sw;
}