SYNOPSIS
cc [flags] files -lnng [libraries]
DESCRIPTION
The nng(7) library provides a common messaging framework intended to solve common communication problems in distributed applications.
It provides a C language API.
Common Functions
The following common functions exist in libnng.
allocate memory |
|
free memory |
|
return an error description |
|
report library version |
Socket Functions
The following functions operate on sockets.
close socket |
|
create and start dialer |
|
get socket option |
|
create and start listener |
|
receive data |
|
send data |
|
set socket option |
Connection Management
The following functions are used with either listeners, or dialers. Listeners accept incoming connection requets, and dialers make them.
create and start dialer |
|
close dialer |
|
create dialer |
|
get dialer option |
|
set dialer option |
|
start dialer |
|
create and start listener |
|
close listener |
|
create listener |
|
get listener option |
|
set listener option |
|
start listener |
Message Handling Functions
Applications desiring to use the richest part of libnng will want to use the message API, where a message structure is passed between functions. This API provides the most power support for zero-copy.
Messages are divided into a header and body, where the body generally carries user-payload and the header carries protocol specific header information. Most applications will only interact with the body.
allocate a message |
|
append to message body |
|
return message body |
|
remove data from end of message body |
|
clear message body |
|
duplicate a message |
|
free a message |
|
prepend to message body |
|
return the message body length |
|
reallocate a message |
|
remove data from start of message body |
|
receive a message |
|
send a message |
Message Header Handling
Few applications will need these functions, as message headers are only used to carry protocol-specific content. However, applications which use raw mode may need to access the header of messages. |
return message header |
|
append to message header |
|
remove data from end of message header |
|
clear message header |
|
prepend to message header |
|
return the message header length |
|
remove data from start of message header |
Asynchronous Operations
Most applications will interact with nng synchronously; that is that functions such as nng_send(3) will block the calling thread until the operation has completed.
Synchronous operations which send messages may return before the message has actually been received, or even transmitted. Instead, These functions return as soon as the message was successfully queued for delivery. |
Asynchronous operations behave differently. These operations are initiated by the calling thread, but control returns immediately to the calling thread. When the operation is subsequently completed (regardless of whether this was successful or not), then a user supplied function ("callback") is executed.
A context structure, called an aio, is allocated and associated for each asynchronous operation. Only a single asynchronous operation may be associated with an aio at any time.
The following functions are used in the asynchronous model:
abort asynchronous I/O operation |
|
allocate asynchronous I/O handle |
|
cancel asynchronous I/O operation |
|
return number of bytes transferred |
|
finish an asynchronous I/O operation |
|
free asynchronous I/O handle |
|
return input parameter |
|
get message from an asynchronous receive |
|
return output result |
|
return result of asynchronous operation |
|
set input parameter |
|
set scatter/gather vector |
|
set message for an asynchronous send |
|
set output result |
|
set asynchronous I/O timeout |
|
stop asynchronous I/O operation |
|
wait for asynchronous I/O operation |
|
receive message asynchronously |
|
send message asynchronously |
Protocols
The following functions are used to construct a socket with a specific protocol:
open a bus socket |
|
open a pair socket |
|
open a pub socket |
|
open a pull socket |
|
open a push socket |
|
open a rep socket |
|
open a req socket |
|
open a respondent socket |
|
open a sub socket |
|
open a surveyor socket |
Transports
The following functions are used to register a transport for use.
register inproc transport |
|
register IPC transport |
|
register TCP transport |
|
register TLS transport |
|
register WebSocket transport |
|
register WebSocket Secure transport |
|
register ZeroTier transport |
URL Object
Common functionality is supplied for parsing and handling universal resource locators (URLS).
clone URL structure |
|
free URL structure |
|
create URL structure from string |
HTTP Support
The library may be configured with support for HTTP, and this will be the case if WebSocket support is configured as well. In this case, it is possible to access functionality to support the creation of HTTP (and HTTP/S if TLS support is present) servers and clients.
Common HTTP Functions
The following functions are used to work with HTTP requests, responses, and connections.
close HTTP connection |
|
read from HTTP connection |
|
read all from HTTP connection |
|
read HTTP request |
|
read HTTP response |
|
write to HTTP connection |
|
write all to HTTP connection |
|
write HTTP request |
|
write HTTP response |
|
add HTTP request header |
|
allocate HTTP request structure |
|
copy HTTP request body |
|
delete HTTP request header |
|
free HTTP request structure |
|
return HTTP request header |
|
return HTTP request method |
|
return HTTP request URI |
|
return HTTP request protocol version |
|
set HTTP request body |
|
set HTTP request header |
|
set HTTP request method |
|
set HTTP request URI |
|
set HTTP request protocol version |
|
add HTTP response header |
|
allocate HTTP response structure |
|
allocate HTTP error response |
|
copy HTTP response body |
|
delete HTTP response header |
|
free HTTP response structure |
|
set HTTP response body |
|
return HTTP response header |
|
return HTTP response reason |
|
return HTTP response status |
|
return HTTP response protocol version |
|
set HTTP response header |
|
set HTTP response reason |
|
set HTTP response status |
|
set HTTP response protocol version |
HTTP Client Functions
These functions are intended for use with HTTP client applications.
allocate HTTP client |
|
establish HTTP client connection |
|
free HTTP client |
|
get HTTP client TLS configuration |
|
set HTTP client TLS configuration |
HTTP Server Functions
These functions are intended for use with HTTP server applications.
allocate HTTP server handler |
|
free HTTP server handler |
|
return extra data for HTTP handler |
|
set extra data for HTTP handler |
|
set host for HTTP handler |
|
set HTTP handler method |
|
set HTTP handler to match trees |
|
hijack HTTP server connection |
|
add HTTP server handler |
|
delete HTTP server handler |
|
get HTTP server TLS configuration |
|
get and hold HTTP server instance |
|
release HTTP server instance |
|
set HTTP server TLS configuration |
|
start HTTP server |
|
stop HTTP server |
TLS Configuration Objects
The following functions are used to manipulate transport layer security (TLS) configuration objects.
These functions will only be present if the library has been built with TLS support. |
allocate TLS configuration |
|
set authentication mode |
|
set certificate authority chain |
|
load certificate authority from file |
|
load own certificate and key from file |
|
set own certificate and key |
|
free TLS configuration |
|
set remote server name |