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
279ce406
Commit
279ce406
authored
Jul 10, 2020
by
legoc
Browse files
(split) Test reset socket
parent
e4a5c66d
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/cameo/Services.cpp
View file @
279ce406
...
...
@@ -172,11 +172,11 @@ std::unique_ptr<OutputStreamSocket> Services::createOutputStreamSocket(int port)
}
std
::
unique_ptr
<
RequestSocketImpl
>
Services
::
createRequestSocket
(
const
std
::
string
&
endpoint
)
{
return
unique_ptr
<
RequestSocketImpl
>
(
new
RequestSocketImpl
(
m_impl
->
createRequestSocket
(
endpoint
)
,
m_impl
->
m_timeout
));
return
unique_ptr
<
RequestSocketImpl
>
(
new
RequestSocketImpl
(
m_impl
.
get
(),
endpoint
,
m_impl
->
m_timeout
));
}
std
::
unique_ptr
<
RequestSocketImpl
>
Services
::
createRequestSocket
(
const
std
::
string
&
endpoint
,
int
timeout
)
{
return
unique_ptr
<
RequestSocketImpl
>
(
new
RequestSocketImpl
(
m_impl
->
createRequestSocket
(
endpoint
)
,
timeout
));
return
unique_ptr
<
RequestSocketImpl
>
(
new
RequestSocketImpl
(
m_impl
.
get
(),
endpoint
,
timeout
));
}
}
src/cameo/impl/RequestSocketImpl.cpp
View file @
279ce406
...
...
@@ -15,6 +15,7 @@
*/
#include "RequestSocketImpl.h"
#include "ServicesImpl.h"
#include "../ConnectionTimeout.h"
#include <iostream>
...
...
@@ -25,10 +26,12 @@ using namespace std;
namespace
cameo
{
RequestSocketImpl
::
RequestSocketImpl
(
zmq
::
socket_t
*
socke
t
,
int
timeout
)
:
m_s
ocket
(
socke
t
)
{
RequestSocketImpl
::
RequestSocketImpl
(
ServicesImpl
*
services
,
const
std
::
string
&
endpoin
t
,
int
timeout
)
:
m_s
ervices
(
services
),
m_endpoint
(
endpoin
t
)
{
setTimeout
(
timeout
);
init
();
}
RequestSocketImpl
::~
RequestSocketImpl
()
{
...
...
@@ -48,8 +51,22 @@ void RequestSocketImpl::setTimeout(int timeout) {
}
}
void
RequestSocketImpl
::
init
()
{
if
(
m_socket
.
get
()
==
nullptr
)
{
m_socket
.
reset
(
m_services
->
createRequestSocket
(
m_endpoint
));
}
}
void
RequestSocketImpl
::
reset
()
{
m_socket
.
reset
();
}
std
::
unique_ptr
<
zmq
::
message_t
>
RequestSocketImpl
::
request
(
const
std
::
string
&
requestTypePart
,
const
std
::
string
&
requestDataPart
,
int
overrideTimeout
)
{
// Init if not already done or if a timeout occurred.
init
();
// Prepare the request parts.
int
requestTypeSize
=
requestTypePart
.
length
();
int
requestDataSize
=
requestDataPart
.
length
();
...
...
@@ -81,6 +98,9 @@ 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();
// Timeout occurred.
throw
ConnectionTimeout
();
}
...
...
src/cameo/impl/RequestSocketImpl.h
View file @
279ce406
...
...
@@ -23,16 +23,23 @@
namespace
cameo
{
class
ServicesImpl
;
class
RequestSocketImpl
{
public:
RequestSocketImpl
(
zmq
::
socket_t
*
socke
t
,
int
timeout
=
0
);
RequestSocketImpl
(
ServicesImpl
*
services
,
const
std
::
string
&
endpoin
t
,
int
timeout
=
0
);
virtual
~
RequestSocketImpl
();
void
setTimeout
(
int
timeout
);
void
init
();
void
reset
();
std
::
unique_ptr
<
zmq
::
message_t
>
request
(
const
std
::
string
&
requestTypePart
,
const
std
::
string
&
requestDataPart
,
int
overrideTimeout
=
-
1
);
ServicesImpl
*
m_services
;
std
::
string
m_endpoint
;
std
::
unique_ptr
<
zmq
::
socket_t
>
m_socket
;
int
m_timeout
;
};
...
...
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