BlueZero (BØ)
Middleware for distributed applications
|
#include <b0/socket.h>
Public Member Functions | |
Socket (Node *node, int type, std::string name, bool managed=true) | |
Construct a Socket. | |
virtual | ~Socket () |
Socket destructor. | |
void | setHasHeader (bool has_header) |
Set the has_header_ flag which specifies if this socket require a message part with the address (usually for publish/subscribe pattern). | |
void | log (LogLevel level, std::string message) const override |
Log a message to the default logger of this node. | |
virtual void | init ()=0 |
Perform initialization (resolve name, connect socket, set subscription) | |
virtual void | cleanup ()=0 |
Perform cleanup (clear subscription, disconnect socket) | |
virtual void | spinOnce () |
Process incoming messages and call callbacks. | |
void | setRemoteAddress (std::string addr) |
Set the remote address the socket will connect to. | |
std::string | getName () const |
Return the name of the socket bus. | |
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. More... | |
virtual void | readRaw (std::string &msg) |
Read a raw payload from the underlying ZeroMQ socket. | |
virtual void | readRaw (std::string &msg, std::string &type) |
Read a raw payload with type from the underlying ZeroMQ socket. | |
virtual bool | poll (long timeout=0) |
Poll for messages. If timeout is 0 return immediately, otherwise wait for the specified amount of milliseconds. | |
virtual void | writeRaw (const std::string &msg, const std::string &type="") |
Write a raw payload. | |
void | setCompression (std::string algorithm, int level=-1) |
Set compression algorithm and level. More... | |
int | getReadTimeout () const |
(low-level socket option) Get read timeout (in milliseconds, -1 for no timeout) | |
void | setReadTimeout (int timeout) |
(low-level socket option) Set read timeout (in milliseconds, -1 for no timeout) | |
int | getWriteTimeout () const |
(low-level socket option) Get write timeout (in milliseconds, -1 for no timeout) | |
void | setWriteTimeout (int timeout) |
(low-level socket option) Set write timeout (in milliseconds, -1 for no timeout) | |
int | getLingerPeriod () const |
(low-level socket option) Get linger period (in milliseconds, -1 for no timeout) | |
void | setLingerPeriod (int period) |
(low-level socket option) Set linger period (in milliseconds, -1 for no timeout) | |
int | getBacklog () const |
(low-level socket option) Get backlog | |
void | setBacklog (int backlog) |
(low-level socket option) Set backlog | |
bool | getImmediate () const |
(low-level socket option) Get immediate flag | |
void | setImmediate (bool immediate) |
(low-level socket option) Set immediate flag | |
bool | getConflate () const |
(low-level socket option) Get conflate flag | |
void | setConflate (bool conflate) |
(low-level socket option) Set conflate flag | |
int | getReadHWM () const |
(low-level socket option) Get read high-water-mark | |
void | setReadHWM (int n) |
(low-level socket option) Set read high-water-mark | |
int | getWriteHWM () const |
(low-level socket option) Get write high-water-mark | |
void | setWriteHWM (int n) |
(low-level socket option) Set write high-water-mark | |
Public Member Functions inherited from b0::logger::LogInterface | |
template<typename... Arguments> | |
void | log (LogLevel level, std::string const &fmt, Arguments &&... args) const |
Log a message using a format string. | |
Protected Member Functions | |
void | connect (std::string const &addr) |
Wrapper to zmq::socket_t::connect. | |
void | disconnect (std::string const &addr) |
Wrapper to zmq::socket_t::disconnect. | |
void | bind (std::string const &addr) |
Wrapper to zmq::socket_t::bind. | |
void | unbind (std::string const &addr) |
Wrapper to zmq::socket_t::unbind. | |
void | setsockopt (int option, const void *optval, size_t optvallen) |
Wrapper to zmq::socket_t::setsockopt. | |
void | getsockopt (int option, void *optval, size_t *optvallen) const |
Wrapper to zmq::socket_t::getsockopt. | |
void | setIntOption (int option, int value) |
High level wrapper for setsockopt. | |
int | getIntOption (int option) const |
High level wrapper for getsockopt. | |
Protected Attributes | |
Node & | node_ |
The Node owning this Socket. | |
std::string | name_ |
This socket bus name. | |
bool | has_header_ |
True if the payload has a header part (i.e. More... | |
const bool | managed_ |
True if this socket is managed (init(), cleanup() are called by the owner Node) | |
std::string | remote_addr_ |
The address of the ZeroMQ socket to connect to (will skip name resolution if given) | |
Additional Inherited Members | |
Public Types inherited from b0::logger::LogInterface | |
enum | LogLevel { trace = 0, debug = 10, info = 20, warn = 30, error = 40, fatal = 50 } |
The Socket class.
This class wraps a ZeroMQ socket. It provides wrappers for reading and writing raw payloads, as well as google::protobuf messages.
bool b0::Socket::matchesPattern | ( | const std::string & | pattern | ) | const |
Check if this socket name matches the specified pattern.
A '*' pattern always matches. A '*.sockName' pattern always matches if sockName matches. A 'nodeName.*' pattern always matches if nodeName matches. A 'nodeName.sockName' pattern matches if bnoth the node name and the socket name match.
void b0::Socket::setCompression | ( | std::string | algorithm, |
int | level = -1 |
||
) |
Set compression algorithm and level.
The messages sent with this socket will be compressed using the specified algorithm. This has no effect on received messages, which will be automatically decompressed using the algorithm specified in the message envelope.
|
protected |
True if the payload has a header part (i.e.
topic). If true, the envelope with this socket name will be prepended to the payload.