Commit 0e3e0ab9 authored by legoc's avatar legoc
Browse files

Simplified ContextZmq

parent d51bb1e7
......@@ -131,14 +131,15 @@ public:
*/
void unregisterEventListener(EventListener * listener);
//TODO private?
Context * getContext();
//TODO private?
Endpoint getStatusEndpoint() const;
//TODO private?
void sendSync();
//TODO private?
void sendSyncStream(const std::string& name);
//TODO private?
int getStreamPort(const std::string& name);
private:
......@@ -169,8 +170,8 @@ private:
std::unique_ptr<RequestSocket> createRequestSocket(const std::string& endpoint);
std::unique_ptr<RequestSocket> createRequestSocket(const std::string& endpoint, int timeout);
Endpoint m_serverEndpoint;
int m_timeout;
std::array<int, 3> m_serverVersion;
int m_statusPort;
std::unique_ptr<ContextZmq> m_contextImpl;
......
......@@ -63,6 +63,7 @@ void Server::initServer(const Endpoint& endpoint, int timeoutMs) {
}
Server::Server(const Endpoint& endpoint, int timeoutMs) :
m_timeout(0),
m_statusPort(0),
m_contextImpl(nullptr) {
......@@ -76,6 +77,7 @@ Server::Server(const Endpoint& endpoint, int timeoutMs) :
}
Server::Server(const std::string& endpoint, int timeoutMs) :
m_timeout(0),
m_statusPort(0),
m_contextImpl(nullptr) {
......@@ -111,7 +113,7 @@ Server::~Server() {
void Server::setTimeout(int timeout) {
m_contextImpl->setTimeout(timeout);
m_timeout = timeout;
if (m_requestSocket.get() != nullptr) {
m_requestSocket->setTimeout(timeout);
......@@ -119,7 +121,7 @@ void Server::setTimeout(int timeout) {
}
int Server::getTimeout() const {
return m_contextImpl->getTimeout();
return m_timeout;
}
const Endpoint& Server::getEndpoint() const {
......@@ -639,7 +641,7 @@ void Server::initContext() {
void Server::initRequestSocket() {
// Create the request socket. The server endpoint must have been initialized.
m_requestSocket = std::move(createRequestSocket(m_serverEndpoint.toString(), m_contextImpl->getTimeout()));
m_requestSocket = std::move(createRequestSocket(m_serverEndpoint.toString(), m_timeout));
}
Context * Server::getContext() {
......@@ -688,7 +690,7 @@ std::unique_ptr<OutputStreamSocket> Server::createOutputStreamSocket(const std::
}
std::unique_ptr<RequestSocket> Server::createRequestSocket(const std::string& endpoint) {
return std::unique_ptr<RequestSocket>(new RequestSocket(m_contextImpl.get(), endpoint, m_contextImpl->getTimeout()));
return std::unique_ptr<RequestSocket>(new RequestSocket(m_contextImpl.get(), endpoint, m_timeout));
}
std::unique_ptr<RequestSocket> Server::createRequestSocket(const std::string& endpoint, int timeout) {
......
......@@ -16,34 +16,17 @@
#include "ContextZmq.h"
#include "SocketException.h"
#include "ConnectionTimeout.h"
#include "JSON.h"
#include "../../Messages.h"
#include "../../RequestSocket.h"
#include <zmq.hpp>
#include <iostream>
#include <sstream>
using namespace std;
namespace cameo {
ContextZmq::ContextZmq() : Context(),
m_context(new zmq::context_t(1)), m_timeout(0) {
m_context(new zmq::context_t(1)) {
}
ContextZmq::~ContextZmq() {
}
void ContextZmq::setTimeout(int timeout) {
m_timeout = timeout;
}
int ContextZmq::getTimeout() const {
return m_timeout;
}
zmq::context_t& ContextZmq::getContext() {
return *m_context.get();
}
......
......@@ -23,28 +23,21 @@
namespace zmq {
class socket_t;
class context_t;
}
namespace cameo {
class RequestSocket;
class ContextZmq : public Context {
public:
ContextZmq();
virtual ~ContextZmq();
void setTimeout(int timeout);
int getTimeout() const;
zmq::context_t& getContext();
private:
std::unique_ptr<zmq::context_t> m_context;
int m_timeout;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment