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

#include <core/system/nanosockets/async_request_socket.hpp>

Public Member Functions

 async_request_socket (std::string target_address, size_t num_connections=2)
 
void close ()
 
int request_master (zmq_msg_vector &msgs, zmq_msg_vector &ret, size_t timeout=0)
 
void set_receive_poller (boost::function< bool()>)
 

Detailed Description

Constructs a nanomsg asynchronous request socket.

The async_request_socket is the requesting endpoint of async_reply_socket. The async_reply_socket listens and waits for requests, and the async_request_socket sends requests. Communication is atomic; either the listener receives all of a message, or none at all. Communication will be automatically retried as needed.

async_request_socket sock("ipc:///tmp/echo_service")
zmq_msg_vector ret;
int ret = sock.request_master(msg, ret, 10); // 10 second timeout

This object is multi-threaded. Calls can be made from multiple threads simultaneously and will be queued accordingly.

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.

Definition at line 45 of file async_request_socket.hpp.

Constructor & Destructor Documentation

◆ async_request_socket()

turi::nanosockets::async_request_socket::async_request_socket ( std::string  target_address,
size_t  num_connections = 2 
)

Constructs a request socket. The request will be sent to the current owners of the key

Parameters
target_addressWhere to connect to
num_connectionsNumber of parallel connections

Member Function Documentation

◆ close()

void turi::nanosockets::async_request_socket::close ( )

Closes this socket. Once closed, the socket cannot be used again.

◆ request_master()

int turi::nanosockets::async_request_socket::request_master ( zmq_msg_vector &  msgs,
zmq_msg_vector &  ret,
size_t  timeout = 0 
)

Sends a request to the server. Returns 0 on success, an error number on failure

Parameters
msgsThe message to send
retThe returned message will be stored here
timeoutNumber of seconds to wait before timeout. Defaults to 0

◆ set_receive_poller()

void turi::nanosockets::async_request_socket::set_receive_poller ( boost::function< bool()>  )

When waiting for a response, this function will be polled once per second. If this function returns false, the receive polling will quit. This can be used for instance, to quit a receive if we know for certain the remote is no longer alive.


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