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
45fd15cb
Commit
45fd15cb
authored
Jul 10, 2020
by
legoc
Browse files
(split2) Test with timeout in Server
parent
4f1bee94
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/cameo/Server.cpp
View file @
45fd15cb
...
...
@@ -30,7 +30,7 @@ using namespace std;
namespace
cameo
{
Server
::
Server
(
const
std
::
string
&
endpoint
)
:
Server
::
Server
(
const
std
::
string
&
endpoint
,
int
timeoutMs
)
:
Services
()
{
Services
::
init
();
...
...
@@ -47,13 +47,26 @@ Server::Server(const std::string& endpoint) :
is
>>
m_port
;
m_serverEndpoint
=
m_url
+
":"
+
port
;
// Set the timeout.
Services
::
setTimeout
(
timeoutMs
);
// Create the request socket. The server endpoint has been defined.
Services
::
initRequestSocket
();
// Start the event thread.
unique_ptr
<
EventStreamSocket
>
socket
=
openEventStream
();
m_eventThread
.
reset
(
new
EventThread
(
this
,
socket
));
m_eventThread
->
start
();
// Manage the ConnectionTimeout exception that can occur.
try
{
// Start the event thread.
unique_ptr
<
EventStreamSocket
>
socket
=
openEventStream
();
m_eventThread
.
reset
(
new
EventThread
(
this
,
socket
));
m_eventThread
->
start
();
}
catch
(
const
std
::
exception
&
e
)
{
cout
<<
"event error "
<<
e
.
what
()
<<
endl
;
}
catch
(...)
{
// ...
}
}
Server
::~
Server
()
{
...
...
src/cameo/Server.h
View file @
45fd15cb
...
...
@@ -48,7 +48,7 @@ class Server : private Services {
public:
typedef
std
::
function
<
void
(
bool
)
>
ConnectionCheckerType
;
Server
(
const
std
::
string
&
endpoint
);
Server
(
const
std
::
string
&
endpoint
,
int
timeoutMs
=
0
);
~
Server
();
void
setTimeout
(
int
timeoutMs
);
...
...
src/cameo/impl/ServicesImpl.cpp
View file @
45fd15cb
...
...
@@ -406,18 +406,27 @@ std::string ServicesImpl::createOutputRequest(const std::string& name) const {
bool
ServicesImpl
::
isAvailable
(
RequestSocketImpl
*
socket
,
int
timeout
)
{
cout
<<
1
<<
endl
;
string
requestTypePart
=
createRequestType
(
PROTO_INIT
);
string
requestDataPart
=
createInitRequest
();
cout
<<
2
<<
endl
;
try
{
unique_ptr
<
zmq
::
message_t
>
reply
=
socket
->
request
(
requestTypePart
,
requestDataPart
,
timeout
);
cout
<<
3
<<
endl
;
if
(
reply
.
get
()
!=
nullptr
)
{
return
true
;
}
}
catch
(
const
ConnectionTimeout
&
)
{
// The server is not accessible.
cout
<<
4
<<
endl
;
}
catch
(
const
std
::
exception
&
e
)
{
cout
<<
"error "
<<
e
.
what
()
<<
endl
;
}
return
false
;
...
...
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