Turi Create
4.0
|
#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()>) |
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.
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.
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
target_address | Where to connect to |
num_connections | Number of parallel connections |
void turi::nanosockets::async_request_socket::close | ( | ) |
Closes this socket. Once closed, the socket cannot be used again.
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
msgs | The message to send |
ret | The returned message will be stored here |
timeout | Number of seconds to wait before timeout. Defaults to 0 |
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.