Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Cameo
cameo
Commits
2ab325b8
Commit
2ab325b8
authored
Mar 05, 2020
by
legoc
Browse files
Corrected implementation of timeout in RequestSocketImpl
parent
22fcb678
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/cameo/Services.cpp
View file @
2ab325b8
...
...
@@ -100,27 +100,23 @@ const std::string& Services::getStatusEndpoint() const {
}
bool
Services
::
isAvailable
(
int
timeout
)
const
{
string
strRequestType
=
m_impl
->
createRequestType
(
PROTO_INIT
);
string
strRequestData
=
m_impl
->
createInitRequest
();
return
m_impl
->
isAvailable
(
strRequestType
,
strRequestData
,
m_serverEndpoint
,
timeout
);
return
m_impl
->
isAvailable
(
m_requestSocket
.
get
(),
timeout
);
}
void
Services
::
initStatus
()
{
// Get the status port.
string
requestTypePart
=
m_impl
->
createRequestType
(
PROTO_STATUS
);
string
requestDataPart
=
m_impl
->
createShowStatusRequest
();
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
requestTypePart
,
requestDataPart
);
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
m_impl
->
createRequestType
(
PROTO_STATUS
),
m_impl
->
createShowStatusRequest
());
proto
::
RequestResponse
requestResponse
;
requestResponse
.
ParseFromArray
((
*
reply
).
data
(),
(
*
reply
).
size
());
//
reply ok
//
Check response.
if
(
requestResponse
.
value
()
==
-
1
)
{
return
;
}
// Get the status port.
m_statusPort
=
requestResponse
.
value
();
stringstream
ss
;
...
...
src/cameo/impl/RequestSocketImpl.cpp
View file @
2ab325b8
...
...
@@ -51,7 +51,7 @@ std::unique_ptr<zmq::message_t> RequestSocketImpl::request(const std::string& re
if
(
timeout
>
0
)
{
// Polling.
zmq_pollitem_t
items
[
1
];
items
[
0
].
socket
=
static_cast
<
void
*>
(
m_socket
.
get
());
items
[
0
].
socket
=
static_cast
<
void
*>
(
*
m_socket
.
get
());
items
[
0
].
fd
=
0
;
items
[
0
].
events
=
ZMQ_POLLIN
;
items
[
0
].
revents
=
0
;
...
...
src/cameo/impl/ServicesImpl.cpp
View file @
2ab325b8
...
...
@@ -20,6 +20,7 @@
#include
<sstream>
#include
"../SocketException.h"
#include
"../ConnectionTimeout.h"
#include
"RequestSocketImpl.h"
// Using Visual Studio preprocessor.
// It must be improved in case of other compilers.
...
...
@@ -505,4 +506,23 @@ void ServicesImpl::subscribeToPublisher(const std::string& endpoint) {
requestResponse
.
ParseFromArray
((
*
reply
).
data
(),
(
*
reply
).
size
());
}
bool
ServicesImpl
::
isAvailable
(
RequestSocketImpl
*
socket
,
int
timeout
)
{
string
requestTypePart
=
createRequestType
(
PROTO_INIT
);
string
requestDataPart
=
createInitRequest
();
try
{
unique_ptr
<
zmq
::
message_t
>
reply
=
socket
->
request
(
requestTypePart
,
requestDataPart
,
timeout
);
if
(
reply
.
get
()
!=
nullptr
)
{
return
true
;
}
}
catch
(
const
ConnectionTimeout
&
)
{
// The server is not accessible.
}
return
false
;
}
}
src/cameo/impl/ServicesImpl.h
View file @
2ab325b8
...
...
@@ -25,6 +25,8 @@
namespace
cameo
{
class
RequestSocketImpl
;
class
ServicesImpl
{
public:
...
...
@@ -72,6 +74,8 @@ public:
void
waitForSubscriber
(
zmq
::
socket_t
*
subscriber
,
const
std
::
string
&
strRequestType
,
const
std
::
string
&
strRequestData
,
const
std
::
string
&
endpoint
);
void
subscribeToPublisher
(
const
std
::
string
&
endpoint
);
bool
isAvailable
(
RequestSocketImpl
*
socket
,
int
timeout
);
zmq
::
context_t
m_context
;
int
m_timeout
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment