NNG 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.
-→
The following functions operate on sockets.
close socket |
|
create and start dialer |
|
get socket option |
|
create and start listener |
|
receive data |
|
send data |
|
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 numeric dialer identifier |
|
set dialer option |
|
start dialer |
|
create and start listener |
|
close listener |
|
create listener |
|
get listener option |
|
get numeric listener identifier |
|
set listener option |
|
start listener |
|
close pipe |
|
return dialer that created pipe |
|
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.
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:
begin asynchronous I/O operation |
|
defer asynchronous I/O operation |
|
finish asynchronous I/O operation |
|
return input parameter |
|
set output result |
|
receive message asynchronously |
|
send message 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 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 numeric context identifier |
|
create context |
|
receive message using context asynchronously |
|
receive a message using context |
|
send message using context asynchronously |
|
send a message using context |
|
set context option |
The following function family is used to create forwarders or relayers that route messages from one socket to another.
message forwarding device |
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 |
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 pre-shared key and identity |
|
set own certificate and key |
|
free TLS configuration |
|
set remote server name |