Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Cameo
cameo
Commits
b587e3da
Commit
b587e3da
authored
Jul 10, 2020
by
legoc
Browse files
Test with timeout in Server
parent
db43649b
Changes
3
Hide whitespace changes
Inline
Side-by-side
cameo-api-cpp/src/cameo/Server.cpp
View file @
b587e3da
...
...
@@ -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
()
{
...
...
cameo-api-cpp/src/cameo/Server.h
View file @
b587e3da
...
...
@@ -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
);
...
...
cameo-api-cpp/src/cameo/impl/ServicesImpl.cpp
View file @
b587e3da
...
...
@@ -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
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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