All Classes Namespaces Functions Variables Typedefs Enumerations Friends
Public Member Functions | Friends | List of all members
ucxx::Listener Class Reference

Component encapsulating a UCP listener. More...

#include <listener.h>

Inheritance diagram for ucxx::Listener:
ucxx::Component

Public Member Functions

 Listener (const Listener &)=delete
 
Listeneroperator= (Listener const &)=delete
 
 Listener (Listener &&o)=delete
 
Listeneroperator= (Listener &&o)=delete
 
std::shared_ptr< EndpointcreateEndpointFromConnRequest (ucp_conn_request_h connRequest, bool endpointErrorHandling=true)
 Constructor for shared_ptr<ucxx::Endpoint>. More...
 
ucp_listener_h getHandle ()
 Get the underlying ucp_listener_h handle. More...
 
uint16_t getPort ()
 Get the port to which the listener is bound to. More...
 
std::string getIp ()
 Get the IP address to which the listener is bound to. More...
 
- Public Member Functions inherited from ucxx::Component
void setParent (std::shared_ptr< Component > parent)
 Set the internal parent reference. More...
 
std::shared_ptr< ComponentgetParent () const
 Get the internal parent reference. More...
 

Friends

std::shared_ptr< ListenercreateListener (std::shared_ptr< Worker > worker, uint16_t port, ucp_listener_conn_callback_t callback, void *callbackArgs)
 Constructor of shared_ptr<ucxx::Listener>. More...
 

Additional Inherited Members

- Protected Attributes inherited from ucxx::Component
std::shared_ptr< Component_parent {nullptr}
 A reference-counted pointer to the parent.
 

Detailed Description

Component encapsulating a UCP listener.

The UCP layer provides a handle to access listeners in form of ucp_listener_h object, this class encapsulates that object and provides methods to simplify its handling.

Member Function Documentation

◆ createEndpointFromConnRequest()

std::shared_ptr<Endpoint> ucxx::Listener::createEndpointFromConnRequest ( ucp_conn_request_h  connRequest,
bool  endpointErrorHandling = true 
)

Constructor for shared_ptr<ucxx::Endpoint>.

The constructor for a shared_ptr<ucxx::Endpoint> object from a ucp_conn_request_h, as delivered by a ucxx::Listener connection callback.

// listener is `std::shared_ptr<ucxx::Listener>`, with a `ucp_conn_request_h` delivered
// by a `ucxx::Listener` connection callback.
auto endpoint = listener->createEndpointFromConnRequest(connRequest, true);
// Equivalent to line above
// auto endpoint = ucxx::createEndpointFromConnRequest(listener, connRequest, true);
Parameters
[in]connRequesthandle to connection request delivered by a listener callback.
[in]endpointErrorHandlingwhether to enable endpoint error handling.
Returns
The shared_ptr<ucxx::Endpoint> object.

◆ getHandle()

ucp_listener_h ucxx::Listener::getHandle ( )

Get the underlying ucp_listener_h handle.

Lifetime of the ucp_listener_h handle is managed by the ucxx::Listener object and its ownership is non-transferrable. Once the ucxx::Listener is destroyed the handle is not valid anymore, it is the user's responsibility to ensure the owner's lifetime while using the handle.

// listener is `std::shared_ptr<ucxx::Listener>`
ucp_listener_h listenerHandle = listener->getHandle();
Returns
The underlying ucp_listener_h handle.

◆ getIp()

std::string ucxx::Listener::getIp ( )

Get the IP address to which the listener is bound to.

Get the IP address to which the listener is bound to.

Returns
the IP address to which the listener is bound to.

◆ getPort()

uint16_t ucxx::Listener::getPort ( )

Get the port to which the listener is bound to.

Get the port to which the listener is bound to.

Returns
the port to which the listener is bound to.

Friends And Related Function Documentation

◆ createListener

std::shared_ptr<Listener> createListener ( std::shared_ptr< Worker worker,
uint16_t  port,
ucp_listener_conn_callback_t  callback,
void *  callbackArgs 
)
friend

Constructor of shared_ptr<ucxx::Listener>.

The constructor for a shared_ptr<ucxx::Listener> object. The default constructor is made private to ensure all UCXX objects are shared pointers for correct lifetime management.

typedef struct ClientContext {
std::shared_ptr<ucxx::Endpoint> endpoint{nullptr};
std::shared_ptr<ucxx::Listener> listener{nullptr};
} ClientContextType;
void myCallback(ucp_conn_request_h connRequest, void* arg) {
ClientContextType clientContext = (ClientContextType*);
clientContext->endpoint =
clientContext->listener->createEndpointFromConnRequest(connRequest);
}
ClientContext clientContext;
// worker is `std::shared_ptr<ucxx::Worker>`
auto listener = worker->createListener(12345, myCallback, clientContext);
clientContext->listener = listener;
// Equivalent to line above
// auto listener = ucxx::createListener(worker, 12345, myCallback, clientContext);
Parameters
[in]workerthe worker from which to create the listener.
[in]portthe port which the listener should be bound to.
[in]callbackuser-defined callback to be executed on incoming client connections.
[in]callbackArgsargument to be passed to the callback.
Returns
The shared_ptr<ucxx::Listener> object.

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