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
4293c55a
Commit
4293c55a
authored
Jul 10, 2020
by
legoc
Browse files
Set the socket linger according to the timeout
parent
c28287f2
Changes
4
Hide whitespace changes
Inline
Side-by-side
cameo-api-cpp/src/cameo/Server.cpp
View file @
4293c55a
...
...
@@ -60,13 +60,9 @@ Server::Server(const std::string& endpoint, int timeoutMs) :
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/impl/RequestSocketImpl.cpp
View file @
4293c55a
...
...
@@ -29,9 +29,9 @@ namespace cameo {
RequestSocketImpl
::
RequestSocketImpl
(
ServicesImpl
*
services
,
const
std
::
string
&
endpoint
,
int
timeout
)
:
m_services
(
services
),
m_endpoint
(
endpoint
)
{
setTimeout
(
timeout
);
init
();
setTimeout
(
timeout
);
}
RequestSocketImpl
::~
RequestSocketImpl
()
{
...
...
@@ -40,6 +40,11 @@ RequestSocketImpl::~RequestSocketImpl() {
void
RequestSocketImpl
::
setTimeout
(
int
timeout
)
{
m_timeout
=
timeout
;
// Apply the linger to the socket.
setSocketLinger
();
}
void
RequestSocketImpl
::
setSocketLinger
()
{
// Set the linger in case of timeout.
// If not, the context can block indefinitely.
// Does the value 100 can lead to a side-effect? A too small value like 1 has some side-effect.
...
...
@@ -53,8 +58,12 @@ void RequestSocketImpl::setTimeout(int timeout) {
void
RequestSocketImpl
::
init
()
{
// Reset if the socket is null.
if
(
m_socket
.
get
()
==
nullptr
)
{
m_socket
.
reset
(
m_services
->
createRequestSocket
(
m_endpoint
));
// Apply the linger to the socket.
setSocketLinger
();
}
}
...
...
@@ -98,7 +107,7 @@ std::unique_ptr<zmq::message_t> RequestSocketImpl::request(const std::string& re
int
rc
=
zmq
::
poll
(
items
,
1
,
timeout
);
if
(
rc
==
0
)
{
// Reset the socket.
// Reset the socket.
It is necessary if a new request is done.
reset
();
// Timeout occurred.
...
...
cameo-api-cpp/src/cameo/impl/RequestSocketImpl.h
View file @
4293c55a
...
...
@@ -32,6 +32,7 @@ public:
virtual
~
RequestSocketImpl
();
void
setTimeout
(
int
timeout
);
void
setSocketLinger
();
void
init
();
void
reset
();
...
...
cameo-api-cpp/src/cameo/impl/ServicesImpl.cpp
View file @
4293c55a
...
...
@@ -406,27 +406,21 @@ 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
&
)
{
}
catch
(
const
ConnectionTimeout
&
)
{
// The server is not accessible.
cout
<<
4
<<
endl
;
}
catch
(
const
std
::
exception
&
e
)
{
cout
<<
"error "
<<
e
.
what
()
<<
endl
;
}
catch
(
...
)
{
// Should not happen.
}
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