Turi Create  4.0
turi::nanosockets::async_reply_socket Class Reference

#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 ()
 

Detailed Description

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:

void echo(zmq_msg_vector& recv, zmq_msg_vector& reply) {
reply = recv;
}
async_reply_socket sock(echo, 4, "ipc:///tmp/echo_service")
sock.start_polling();

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,

See also
async_request_socket

Definition at line 52 of file async_reply_socket.hpp.

Member Typedef Documentation

◆ callback_type

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.

Note
There is no provided way to figure out if a reply is necessary. This must be managed on a higher protocol layer.

Definition at line 64 of file async_reply_socket.hpp.

Constructor & Destructor Documentation

◆ async_reply_socket()

turi::nanosockets::async_reply_socket::async_reply_socket ( callback_type  callback,
size_t  nthreads = 4,
std::string  bind_address = "" 
)

Constructs a reply socket.

Parameters
callbackThe function used to process replies. Multiple threads may call the callback simultaneously
nthreadsThe maximum number of threads to use
alternate_bind_addressIf set, this will be address to bind to. Otherwise, binds to a free tcp address.

Member Function Documentation

◆ close()

void turi::nanosockets::async_reply_socket::close ( )

Closes the socket. Once closed. It cannot be opened again

◆ get_bound_address()

std::string turi::nanosockets::async_reply_socket::get_bound_address ( )

Returns the address the socket is bound to


The documentation for this class was generated from the following file: