1 #ifndef B0__SOCKET_H__INCLUDED 2 #define B0__SOCKET_H__INCLUDED 6 #include <b0/user_data.h> 7 #include <b0/logger/interface.h> 9 #include <boost/function.hpp> 10 #include <boost/bind.hpp> 37 Socket(
Node *node,
int type, std::string name,
bool managed =
true);
53 void log(
LogLevel level, std::string message)
const override;
58 virtual void init() = 0;
96 std::unique_ptr<SocketPrivate> private_;
119 virtual void readRaw(std::string &msg);
124 virtual void readRaw(std::string &msg, std::string &type);
130 virtual bool poll(
long timeout = 0);
135 virtual void writeRaw(
const std::string &msg,
const std::string &type =
"");
150 std::string compression_algorithm_;
154 int compression_level_;
207 void connect(std::string
const &addr);
213 void bind(std::string
const &addr);
216 void unbind(std::string
const &addr);
219 void setsockopt(
int option,
const void *optval,
size_t optvallen);
222 void getsockopt(
int option,
void *optval,
size_t *optvallen)
const;
233 #endif // B0__SOCKET_H__INCLUDED void unbind(std::string const &addr)
Wrapper to zmq::socket_t::unbind.
LogLevel
Definition: interface.h:23
virtual void spinOnce()
Process incoming messages and call callbacks.
int getBacklog() const
(low-level socket option) Get backlog
void log(LogLevel level, std::string message) const override
Log a message to the default logger of this node.
virtual bool poll(long timeout=0)
Poll for messages. If timeout is 0 return immediately, otherwise wait for the specified amount of mil...
void setIntOption(int option, int value)
High level wrapper for setsockopt.
void getsockopt(int option, void *optval, size_t *optvallen) const
Wrapper to zmq::socket_t::getsockopt.
virtual void readRaw(std::string &msg)
Read a raw payload from the underlying ZeroMQ socket.
Socket(Node *node, int type, std::string name, bool managed=true)
Construct a Socket.
void setImmediate(bool immediate)
(low-level socket option) Set immediate flag
int getReadHWM() const
(low-level socket option) Get read high-water-mark
Node & node_
The Node owning this Socket.
Definition: socket.h:100
bool has_header_
True if the payload has a header part (i.e.
Definition: socket.h:107
void bind(std::string const &addr)
Wrapper to zmq::socket_t::bind.
virtual void writeRaw(const std::string &msg, const std::string &type="")
Write a raw payload.
std::string name_
This socket bus name.
Definition: socket.h:103
int getIntOption(int option) const
High level wrapper for getsockopt.
std::string getName() const
Return the name of the socket bus.
bool getImmediate() const
(low-level socket option) Get immediate flag
The abstraction for a node in the network.
Definition: node.h:40
void connect(std::string const &addr)
Wrapper to zmq::socket_t::connect.
void setReadHWM(int n)
(low-level socket option) Set read high-water-mark
void setWriteHWM(int n)
(low-level socket option) Set write high-water-mark
void setCompression(std::string algorithm, int level=-1)
Set compression algorithm and level.
Node & getNode() const
Return the node owning this socket.
bool matchesPattern(const std::string &pattern) const
Check if this socket name matches the specified pattern.
virtual void init()=0
Perform initialization (resolve name, connect socket, set subscription)
void setBacklog(int backlog)
(low-level socket option) Set backlog
virtual ~Socket()
Socket destructor.
int getReadTimeout() const
(low-level socket option) Get read timeout (in milliseconds, -1 for no timeout)
void setsockopt(int option, const void *optval, size_t optvallen)
Wrapper to zmq::socket_t::setsockopt.
void disconnect(std::string const &addr)
Wrapper to zmq::socket_t::disconnect.
The Socket class.
Definition: socket.h:31
void setWriteTimeout(int timeout)
(low-level socket option) Set write timeout (in milliseconds, -1 for no timeout)
bool getConflate() const
(low-level socket option) Get conflate flag
void setLingerPeriod(int period)
(low-level socket option) Set linger period (in milliseconds, -1 for no timeout)
void setRemoteAddress(std::string addr)
Set the remote address the socket will connect to.
int getWriteHWM() const
(low-level socket option) Get write high-water-mark
void setReadTimeout(int timeout)
(low-level socket option) Set read timeout (in milliseconds, -1 for no timeout)
std::string remote_addr_
The address of the ZeroMQ socket to connect to (will skip name resolution if given) ...
Definition: socket.h:113
void setConflate(bool conflate)
(low-level socket option) Set conflate flag
Base class to add logging functionalities to nodes.
Definition: interface.h:17
int getLingerPeriod() const
(low-level socket option) Get linger period (in milliseconds, -1 for no timeout)
const bool managed_
True if this socket is managed (init(), cleanup() are called by the owner Node)
Definition: socket.h:110
virtual void cleanup()=0
Perform cleanup (clear subscription, disconnect socket)
int getWriteTimeout() const
(low-level socket option) Get write timeout (in milliseconds, -1 for no timeout)
void setHasHeader(bool has_header)
Set the has_header_ flag which specifies if this socket require a message part with the address (usua...