Chapter 48. Registering an application

#include <x/fd.H>
#include <x/httportmap.H>

x::fd socket(x::fd::base::socket(AF_INET6, SOCK_STREAM));

socket->bind(x::sockaddr::create(AF_INET6, "", 0));

x::httportmap portmapper(x::httportmap::create());

if (!portmapper->reg("", socket,
    std::cerr << "Application already started"  << std::endl;

This example creates and listens on an AF_INET6 socket (on Linux, AF_INET6 sockets, by default, also accept IPv4 connections). A default x::httportmap instance represents a connection to a portmapper daemon on the same server. reg() registers the listening socket with the portmapper under the application name of

Application names are arbitrary labels, however they may not contain any control characters, and they should be valid domain names or email addresses, and applications should use only Internet domains that they own. This way, the application name domain is globally unique and different applications names will not clash. This implementation reserves application names ending with .libcxx for internal use.

All applications are registered by their name AND the application's userid. The third parameter to reg() indicates whether the application registration is exclusive. If true, the portmapper will not register the same application name and userid more than once. The portmapper accepts the same application name registered by different userids. If false, the same userid can register the same application name more than once.

Multiple services may be registered through the same portmapper object. The port remains registered as long as the portmapper object remains in scope. The portmapper object maintains an open socket connection with the local portmapper daemon. When the process terminates, or when the portmapper object goes out of scope and gets destroyed, all services registered by the object gets deregistered.


The default portmapper configuration limits each process to ten registered services, at a time.