Simplify the handling of send/receive timeouts

This commit is contained in:
Alexey Rybalchenko 2015-11-19 15:30:37 +01:00 committed by Florian Uhlig
parent 0894900f52
commit afda64a83d
3 changed files with 53 additions and 73 deletions

View File

@ -583,60 +583,62 @@ int FairMQChannel::Receive(FairMQMessage* msg, const int flags) const
} }
} }
bool FairMQChannel::SetSendTimeout(const int timeout) void FairMQChannel::SetSendTimeout(const int timeout)
{ {
if (fSocket) // if (fSocket)
{ // {
if (fSocket->SetSendTimeout(timeout, fAddress, fMethod)) // if (fSocket->SetSendTimeout(timeout, fAddress, fMethod))
{ // {
fSndTimeoutInMs = timeout; fSndTimeoutInMs = timeout;
return true; // return true;
} // }
} // }
LOG(ERROR) << "SetSendTimeout() failed - socket is not initialized!"; // LOG(ERROR) << "SetSendTimeout() failed - socket is not initialized!";
return false; // return false;
} }
int FairMQChannel::GetSendTimeout() const int FairMQChannel::GetSendTimeout() const
{ {
if (fSocket) return fSndTimeoutInMs;
{ // if (fSocket)
return fSocket->GetSendTimeout(); // {
} // return fSocket->GetSendTimeout();
else // }
{ // else
LOG(ERROR) << "GetSendTimeout() failed - socket is not initialized!"; // {
return -1; // LOG(ERROR) << "GetSendTimeout() failed - socket is not initialized!";
} // return -1;
// }
} }
bool FairMQChannel::SetReceiveTimeout(const int timeout) void FairMQChannel::SetReceiveTimeout(const int timeout)
{ {
if (fSocket) // if (fSocket)
{ // {
if (fSocket->SetReceiveTimeout(timeout, fAddress, fMethod)) // if (fSocket->SetReceiveTimeout(timeout, fAddress, fMethod))
{ // {
fRcvTimeoutInMs = timeout; fRcvTimeoutInMs = timeout;
return true; // return true;
} // }
} // }
LOG(ERROR) << "SetReceiveTimeout() failed - socket is not initialized!"; // LOG(ERROR) << "SetReceiveTimeout() failed - socket is not initialized!";
return false; // return false;
} }
int FairMQChannel::GetReceiveTimeout() const int FairMQChannel::GetReceiveTimeout() const
{ {
if (fSocket) return fRcvTimeoutInMs;
{ // if (fSocket)
return fSocket->GetReceiveTimeout(); // {
} // return fSocket->GetReceiveTimeout();
else // }
{ // else
LOG(ERROR) << "GetReceiveTimeout() failed - socket is not initialized!"; // {
return -1; // LOG(ERROR) << "GetReceiveTimeout() failed - socket is not initialized!";
} // return -1;
// }
} }
bool FairMQChannel::ExpectsAnotherPart() const bool FairMQChannel::ExpectsAnotherPart() const

View File

@ -161,8 +161,7 @@ class FairMQChannel
/// Sets a timeout on the (blocking) Send method /// Sets a timeout on the (blocking) Send method
/// @param timeout timeout value in milliseconds /// @param timeout timeout value in milliseconds
/// @return true if operation was successfull, otherwise false. void SetSendTimeout(const int timeout);
bool SetSendTimeout(const int timeout);
/// Gets the current value of the timeout on the (blocking) Send method /// Gets the current value of the timeout on the (blocking) Send method
/// @return Timeout value in milliseconds. -1 for no timeout. /// @return Timeout value in milliseconds. -1 for no timeout.
@ -170,8 +169,7 @@ class FairMQChannel
/// Sets a timeout on the (blocking) Receive method /// Sets a timeout on the (blocking) Receive method
/// @param timeout timeout value in milliseconds /// @param timeout timeout value in milliseconds
/// @return true if operation was successfull, otherwise false. void SetReceiveTimeout(const int timeout);
bool SetReceiveTimeout(const int timeout);
/// Gets the current value of the timeout on the (blocking) Receive method /// Gets the current value of the timeout on the (blocking) Receive method
/// @return Timeout value in milliseconds. -1 for no timeout. /// @return Timeout value in milliseconds. -1 for no timeout.

View File

@ -37,47 +37,27 @@ class TransferTimeoutTester : public FairMQDevice
bool sendCanceling = false; bool sendCanceling = false;
bool receiveCanceling = false; bool receiveCanceling = false;
if (fChannels.at("data-out").at(0).SetSendTimeout(1000)) fChannels.at("data-out").at(0).SetSendTimeout(1000);
fChannels.at("data-in").at(0).SetReceiveTimeout(1000);
if (fChannels.at("data-out").at(0).GetSendTimeout() == 1000)
{ {
setSndOK = true; getSndOK = true;
LOG(INFO) << "set send timeout OK"; LOG(INFO) << "get send timeout OK: " << fChannels.at("data-out").at(0).GetSendTimeout();
} }
else else
{ {
LOG(ERROR) << "set send timeout failed"; LOG(ERROR) << "get send timeout failed";
} }
if (fChannels.at("data-in").at(0).SetReceiveTimeout(1000)) if (fChannels.at("data-in").at(0).GetReceiveTimeout() == 1000)
{ {
setRcvOK = true; getRcvOK = true;
LOG(INFO) << "set receive timeout OK"; LOG(INFO) << "get receive timeout OK: " << fChannels.at("data-in").at(0).GetReceiveTimeout();
} }
else else
{ {
LOG(ERROR) << "set receive timeout failed"; LOG(ERROR) << "get receive timeout failed";
}
if (setSndOK && setRcvOK)
{
if (fChannels.at("data-out").at(0).GetSendTimeout() == 1000)
{
getSndOK = true;
LOG(INFO) << "get send timeout OK: " << fChannels.at("data-out").at(0).GetSendTimeout();
}
else
{
LOG(ERROR) << "get send timeout failed";
}
if (fChannels.at("data-in").at(0).GetReceiveTimeout() == 1000)
{
getRcvOK = true;
LOG(INFO) << "get receive timeout OK: " << fChannels.at("data-in").at(0).GetReceiveTimeout();
}
else
{
LOG(ERROR) << "get receive timeout failed";
}
} }
if (getSndOK && getRcvOK) if (getSndOK && getRcvOK)