- create a port
#include <port.h> int port_create(void);
The port_create() function establishes a queue that multiplexes events from disjoint sources. Each source has a corresponding object type and source-specific mechanism for associating an object with a port.
PORT_SOURCE_AIO events represent the completion of an asynchronous I/O transaction. An asynchronous I/O transaction is associated with a port by specifying SIGEV_PORT as its notification mechanism. See aio_read(3RT), aio_write(3RT), lio_listio(3RT), and aio.h(3HEAD) for details.
PORT_SOURCE_FD events represent a transition in the poll(2) status of a given file descriptor. Once an event is delivered, the file descriptor is no longer associated with the port. A file descriptor is associated (or re-associated) with a port using the port_associate(3C) function.
PORT_SOURCE_TIMER events represent one or more timer expirations for a given timer. A timer is associated with a port by specifying SIGEV_PORT as its notification mechanism. See timer_create(3RT) for more information.
PORT_SOURCE_ALERT events indicate that the port itself is in alert mode. The mode of the port is changed with port_alert(3C).The port_create() function returns a file descriptor that represents a newly created port. The close(2) function destroys the port and frees all allocated resources.
As a port is represented by a file descriptor, ports are shared between child and parent processes after fork(). Both can continue to associate sources with the port, both can receive events from the port, and events associated with and/or generated by either process are retrievable in the other. Since some events might not have meaning in both parent and child, care must be taken when using ports after fork().
If a port is exported to other processes, the port is destroyed on last close.
PORT_SOURCE_USER and PORT_SOURCE_ALERT events can be distributed across processes. PORT_SOURCE_FD events can only be shared between processes when child processes inherit opened file decriptors from the parent process. See fork(2). PORT_SOURCE_TIMER and PORT_SOURCE_AIO cannot be shared between processes.
Upon succesful completion, the port_create() function returns a non-negative value, the port identifier. Otherwise, -1 is returned and errno is set to indicate the error.
The port_create() function will fail if:
The maximum allowable number of ports is currently open in the system. The maximum allowable number of ports is the minimum value of the project.max-port-ids resource control. See setrctl(2) and rctladm(1M) for information on using resource controls.
The process has too many open descriptors.
See attributes(5) for descriptions of the following attributes: