NNG provides a common messaging framework intended to solve common communication problems in distributed applications.
It provides a C language API.
The following common functions exist in libnng.
allocate memory |
|
free memory |
|
duplicate string |
|
return an error description |
|
free string |
|
report library version |
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 |
|
get socket option |
|
get numeric socket identifier |
|
set socket option |
The following functions are used with either listeners, or dialers. Listeners accept incoming connection requests, and dialers make them.
create and start dialer |
|
close dialer |
|
create dialer |
|
get dialer option |
|
get dialer option |
|
get numeric dialer identifier |
|
set dialer option |
|
set dialer option |
|
start dialer |
|
create and start listener |
|
close listener |
|
create listener |
|
get listener option |
|
get listener option |
|
get numeric listener identifier |
|
set listener option |
|
set listener option |
|
start listener |
|
close pipe |
|
return dialer that created pipe |
|
get pipe option |
|
get pipe option |
|
get numeric pipe identifier |
|
return listener that created pipe |
|
register pipe notification callback |
|
return owning socket for pipe |
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 |
|
get pipe for message |
|
prepend to message body |
|
return the message body length |
|
reallocate a message |
|
set pipe for message |
|
remove data from start of message body |
|
receive a message |
|
send a message |
Tip
|
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 |
Most applications will interact with NNG synchronously; that is that
functions such as nng_send()
will block the calling
thread until the operation has completed.
Note
|
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 is executed.
A context structure, an nng_aio
, is allocated and
associated with each asynchronous operation.
Only a single asynchronous operation may be associated with an
nng_aio
at any time.
The following functions are used in the asynchronous model:
abort asynchronous I/O operation |
|
allocate asynchronous I/O handle |
|
begin asynchronous I/O operation |
|
cancel asynchronous I/O operation |
|
return number of bytes transferred |
|
defer asynchronous I/O operation |
|
finish asynchronous I/O operation |
|
free asynchronous I/O handle |
|
return input parameter |
|
get message from an asynchronous receive |
|
return output result |
|
reap asynchronous I/O handle |
|
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 |
|
sleep asynchronously |
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 |
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 |
The following functions are useful to separate the protocol processing from a socket object, into a separate context. This can allow multiple contexts to be created on a single socket for concurrent applications.
close context |
|
get context option |
|
get context option |
|
get numeric context identifier |
|
create context |
|
receive message using context asynchronously |
|
send message using context asynchronously |
|
set context option |
|
set context option |
The following functions provide access to statistics which can be used to observe program behaviors and as an aid in troubleshooting.
get statistic Boolean value |
|
get child statistic |
|
get statistic description |
|
find statistic by name |
|
find dialer statistics |
|
find listener statistics |
|
find socket statistics |
|
get statistic name |
|
get next statistic |
|
get statistic string value |
|
get statistic timestamp |
|
get statistic type |
|
get statistic unit |
|
get statistic numeric value |
|
free statistics |
|
get statistics |
Common functionality is supplied for parsing and handling universal resource locators (URLS).
clone URL structure |
|
free URL structure |
|
create URL structure from string |
These supplemental functions are not intrinsic to building network applications with NNG, but they are made available as a convenience to aid in creating portable applications.
get time |
|
allocate condition variable |
|
free condition variable |
|
wait for condition or timeout |
|
wait for condition |
|
wake all waiters |
|
wake one waiter |
|
sleep for milliseconds |
|
allocate mutex |
|
free mutex |
|
lock mutex |
|
unlock mutex |
|
parse command line options |
|
get random number |
|
create thread |
|
reap thread |
|
set thread name |
These functions are available for use with byte streams. They are considered low-level, for uses where the higher level functions using Scalability Protocols are inappropriate.
Byte streams, represented by
nng_stream
objects, correspond to underlying
connections such as TCP connections or named pipes.
They are created by either
nng_stream_dialer
or
nng_stream_listener
objects.
close byte stream |
|
allocate byte stream dialer |
|
close byte stream dialer |
|
initiate outgoing byte stream |
|
free byte stream dialer |
|
get option from byte stream dialer |
|
set option on byte stream dialer |
|
free byte stream |
|
get option from byte stream |
|
accept incoming byte stream |
|
allocate byte stream listener |
|
close byte stream listener |
|
free byte stream listener |
|
get option from byte stream listener |
|
bind byte stream listener to address |
|
set option on byte stream listener |
|
receive from byte stream |
|
send to byte stream |
|
set option on byte stream |
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.
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 |
|
get HTTP request body |
|
return HTTP request header |
|
return HTTP request method |
|
return HTTP request URI |
|
return HTTP request protocol version |
|
reset HTTP request structure |
|
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 |
|
get HTTP response body |
|
return HTTP response header |
|
return HTTP response reason |
|
return HTTP response status |
|
return HTTP response protocol version |
|
reset HTTP response structure |
|
set HTTP response body |
|
set HTTP response header |
|
set HTTP response reason |
|
set HTTP response status |
|
set HTTP response protocol version |
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 |
|
perform one HTTP transaction |
|
perform one HTTP transaction on connection |
These functions are intended for use with HTTP server applications.
allocate HTTP server handler |
|
set HTTP handler to collect request body |
|
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 address |
|
get HTTP server TLS configuration |
|
get and hold HTTP server instance |
|
release HTTP server instance |
|
set custom HTTP error file |
|
set custom HTTP error page |
|
set HTTP server TLS configuration |
|
use HTTP server error page |
|
start HTTP server |
|
stop HTTP server |
The following functions are used to manipulate transport layer security (TLS) configuration objects. Most of these functions will not be used even by TLS applications.
Note
|
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 |