Skip to content

Commit

Permalink
Updated RWS subscription timeout implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jontje committed Feb 22, 2019
1 parent dde2af1 commit 9af439c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions include/abb_librws/rws_client.h
Expand Up @@ -706,6 +706,11 @@ class RWSClient : public POCOClient
*/
static const size_t LOG_SIZE = 20;

/**
* \brief Static constant for the default RWS subscription timeout [microseconds].
*/
static const Poco::Int64 DEFAULT_SUBSCRIPTION_TIMEOUT = 40000000;

/**
* \brief Container for logging communication results.
*/
Expand Down
3 changes: 2 additions & 1 deletion include/abb_librws/rws_poco_client.h
Expand Up @@ -328,10 +328,11 @@ class POCOClient
*
* \param uri for the URI (path and query).
* \param protocol for the WebSocket protocol.
* \param timeout for the WebSocket communication timeout [microseconds].
*
* \return POCOResult containing the result.
*/
POCOResult webSocketConnect(const std::string uri, const std::string protocol);
POCOResult webSocketConnect(const std::string uri, const std::string protocol, const Poco::Int64 timeout);

/**
* \brief A method for receiving a WebSocket frame.
Expand Down
3 changes: 2 additions & 1 deletion src/rws_client.cpp
Expand Up @@ -425,7 +425,8 @@ RWSClient::RWSResult RWSClient::startSubscription(SubscriptionResources resource
evaluation_conditions_.reset();
evaluation_conditions_.parse_message_into_xml = false;
evaluation_conditions_.accepted_outcomes.push_back(HTTPResponse::HTTP_SWITCHING_PROTOCOLS);
result = evaluatePOCOResult(webSocketConnect(poll, "robapi2_subscription"), evaluation_conditions_);
result = evaluatePOCOResult(webSocketConnect(poll, "robapi2_subscription", DEFAULT_SUBSCRIPTION_TIMEOUT),
evaluation_conditions_);

if(!result.success)
{
Expand Down
6 changes: 4 additions & 2 deletions src/rws_poco_client.cpp
Expand Up @@ -314,7 +314,9 @@ POCOClient::POCOResult POCOClient::makeHTTPRequest(const std::string method,
return result;
}

POCOClient::POCOResult POCOClient::webSocketConnect(const std::string uri, const std::string protocol)
POCOClient::POCOResult POCOClient::webSocketConnect(const std::string uri,
const std::string protocol,
const Poco::Int64 timeout)
{
// Lock the object's mutex. It is released when the method goes out of scope.
ScopedLock<Mutex> lock(http_mutex_);
Expand All @@ -333,7 +335,7 @@ POCOClient::POCOResult POCOClient::webSocketConnect(const std::string uri, const
{
result.addHTTPRequestInfo(request);
p_websocket_ = new WebSocket(http_client_session_, request, response);
p_websocket_->setReceiveTimeout(Poco::Timespan(LONG_TIMEOUT));
p_websocket_->setReceiveTimeout(Poco::Timespan(timeout));

result.addHTTPResponseInfo(response);
result.status = POCOResult::OK;
Expand Down

0 comments on commit 9af439c

Please sign in to comment.