Turi Create
4.0
|
#include <core/system/nanosockets/async_reply_socket.hpp>
Public Types | |
typedef boost::function< bool(zmq_msg_vector &recv, zmq_msg_vector &reply)> | callback_type |
Public Member Functions | |
async_reply_socket (callback_type callback, size_t nthreads=4, std::string bind_address="") | |
void | close () |
std::string | get_bound_address () |
A nanomsg asynchronous reply socket.
The Asynchronous reply socket is the target endpoint of the the asynchronous request socket (async_request_socket). The reply socket listens on an endpoint, and the request socket sends requests to an endpoint. Endpoints are standard Zeromq style endpoint addresses , for instance, tcp://[ip]:[port], or ipc://[filename] (interprocess socket) or inproc://[handlename] (inprocess socket). Ipc sockets are emulated on windows using TCP.
The asynchronous reply socket is constructed with a callback which is called whenever a request is received. The callback may be called in parallel; up to the value of nthreads. For instance, a simple echo service can be built with:
All messaging is done via zmq_msg_vector which is internally, an array of nn_msg_t objects. Message boundaries are preserved across the wire; i.e. if a request of 4 messages is sent, we will receive exactly a zmq_msg_vector of 4 messages.
Also,
Definition at line 52 of file async_reply_socket.hpp.
typedef boost::function<bool (zmq_msg_vector& recv, zmq_msg_vector& reply)> turi::nanosockets::async_reply_socket::callback_type |
Returns true if there are contents to reply. Returns false otherwise. If the reply socket is connected to a request socket, this must always return true.
Definition at line 64 of file async_reply_socket.hpp.
turi::nanosockets::async_reply_socket::async_reply_socket | ( | callback_type | callback, |
size_t | nthreads = 4 , |
||
std::string | bind_address = "" |
||
) |
Constructs a reply socket.
callback | The function used to process replies. Multiple threads may call the callback simultaneously |
nthreads | The maximum number of threads to use |
alternate_bind_address | If set, this will be address to bind to. Otherwise, binds to a free tcp address. |
void turi::nanosockets::async_reply_socket::close | ( | ) |
Closes the socket. Once closed. It cannot be opened again
std::string turi::nanosockets::async_reply_socket::get_bound_address | ( | ) |
Returns the address the socket is bound to