From 2b8d71694ea8755881bdb8d8fe1fdcc9d4055eac Mon Sep 17 00:00:00 2001 From: gdamore Date: Wed, 15 Jan 2025 05:56:53 +0000 Subject: deploy: 575148ac9a274d61e45220fda7d8de6a420f4fe4 --- ref/api/ctx.html | 4 +- ref/api/http.html | 51 ++++--- ref/api/index.html | 1 + ref/api/memory.html | 4 +- ref/api/msg.html | 2 +- ref/api/pipe.html | 432 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ref/api/sock.html | 2 +- ref/api/stream.html | 2 +- 8 files changed, 466 insertions(+), 32 deletions(-) create mode 100644 ref/api/pipe.html (limited to 'ref/api') diff --git a/ref/api/ctx.html b/ref/api/ctx.html index 306d596d..c0082b33 100644 --- a/ref/api/ctx.html +++ b/ref/api/ctx.html @@ -463,7 +463,7 @@ start_echo_service(nng_socket rep_socket) - @@ -477,7 +477,7 @@ start_echo_service(nng_socket rep_socket) - diff --git a/ref/api/http.html b/ref/api/http.html index 19c182af..03ab3ef6 100644 --- a/ref/api/http.html +++ b/ref/api/http.html @@ -306,9 +306,10 @@ const char *nng_http_get_reason(nng_http_conn *conn); void nng_http_set_status(nng_http *conn, nng_http_status status, const char *reason);

The nng_http_get_status function obtains the numeric code (typipcally numbered from 100 through 599) returned -by the server in the last exchange on conn. (If no exchange has been performed yet, the result is undefined.)

-

A descriptive message matching the status code is returned by nng_http_get_reason.

-

The nng_http_set_status function is used on a server in a handler callback to set the status code that will be +by the server in the last exchange on conn. (If no exchange has been performed yet, the result is undefined.) +The value is returned as an nng_http_status.

+

A descriptive message matching the status code is returned by nng_http_get_reason.

+

The nng_http_set_status function is used on a server in a handler callback to set the status code that will be reported to the client to status, and the associated text (reason) to reason. If reason is NULL, then a built in reason based on the status will be used instead.

@@ -388,14 +389,14 @@ for display to users.

const char *nng_http_get_header(nng_http *conn, const char *key);
 bool nng_next_header(nng_http *conn, const char **keyp, const char **valuep, void **next);
 
-

The nng_http_get_header returns the header value matching key that was received over conn, +

The nng_http_get_header returns the header value matching key that was received over conn, or NULL if no such header exists.

Thus, if conn is a client connection, then this function returns the the header value sent by the server as part of a response, whereas if it is a server connection, it returns the header value sent by the client as part of the request.

If multiple headers are present with the same key, they may be returned as a combined value, with individual values separated by commas, but this behavior is not guaranteed.

-

The nng_http_next_header function iterates over all the headers, using the same list +

The nng_http_next_header function iterates over all the headers, using the same list that nng_http_get_header uses. To start, it is called with next initialized to NULL. If a header was found, then it returns true, and sets keyp and valuep to values containing the header name and value. It also updates next, which should be used for the next iteration.

@@ -406,7 +407,7 @@ The scan can be rest by setting next to NULL.

nng_err nng_http_set_header(nng_http *conn, const char *key, const char *val); void nng_http_del_header(nng_http *conn, const char *key); -

The nng_http_add_header, nng_http_set_header, and nng_http_del_header functions are +

The nng_http_add_header, nng_http_set_header, and nng_http_del_header functions are used to add a modify either the request or response headers for conn prior to sending to the connected peer on conn.

Thus, if the conn is a client connection created by nng_http_client_connect, then the request headers are modified. Conversely, if it is a connection created by an HTTP server and used in a callback function, then the response headers are modified.

@@ -428,7 +429,7 @@ as by guaranting that only a single instance of one of these headers is present.

Retrieving Body Content

void nng_http_get_body(nng_http_conn *conn, void **datap, size_t *sizep);
 
-

The nng_http_get_data obtains the most recently received request or +

The nng_http_get_data obtains the most recently received request or response body. This will be NULL if the content has not been retrieved properly yet, or if the peer did not any content. (Some requests are defined to never have body content, such as “HEAD”.)

@@ -436,10 +437,10 @@ to never have body content, such as “HEAD”.)

void nng_http_set_body(nng_http_conn *conn, void *data, size_t size);
 void nng_http_copy_body(nng_http_conn *conn, const void *data, size_t size);
 
-

The nng_http_set_data function sets the outgoing body content to data, +

The nng_http_set_data function sets the outgoing body content to data, which must be size bytes long. The caller must ensure that data remains valid for the duration of the transaction.

-

The nng_http_copy_data function makes a copy of data, which +

The nng_http_copy_data function makes a copy of data, which will be freed automatically when the transaction is finished, but otherwise behaves like nng_http_set_data.

On client conn objects, these functions update the request object, but on server @@ -463,13 +464,13 @@ transfer-encoding.

Closing the Connection

void nng_http_close(nng_http *conn);
 
-

The nng_http_close function closes the supplied HTTP connection conn, +

The nng_http_close function closes the supplied HTTP connection conn, including any disposing of any underlying file descriptors or related resources.

Once this function, no further access to the conn structure may be made.

Reset Connection State

void nng_http_reset(nng_http *conn);
 
-

The nng_http_reset function resets the request and response state of the +

The nng_http_reset function resets the request and response state of the the connection conn, so that it is just as if it had been freshly created with nng_http_client_connect or passed into a handler function for a server callback.

The intended purpose of this function is to clear the object state before reusing the conn for @@ -480,11 +481,11 @@ void nng_http_write(nng_http *conn, nng_aio *aio); void nng_http_read_all(nng_http *conn, nng_aio *aio); void nng_http_write_all(nng_http *conn, nng_aio *aio); -

The nng_http_read and nng_http_write functions read or write data asynchronously from or to the +

The nng_http_read and nng_http_write functions read or write data asynchronously from or to the connection conn, using the nng_iov that is set in aio with nng_aio_set_iov. These functions will complete as soon as any data is transferred. Use nng_aio_count to determine how much data was actually transferred.

-

The nng_http_read_all and nng_http_write_all functions perform the same task, but will keep resubmitting +

The nng_http_read_all and nng_http_write_all functions perform the same task, but will keep resubmitting operations until the the entire amount of data requested by the nng_iov is transferred.

@@ -499,7 +500,7 @@ They can be used to transfer request or response body data as well.

nng_err nng_http_hijack(nng_http *conn);
 

TODO: This API will change to convert the conn into a stream object.

-

The nng_http_hijack function hijacks the connection conn, causing it +

The nng_http_hijack function hijacks the connection conn, causing it to be disassociated from the HTTP server where it was created.

The purpose of this function is the creation of HTTP upgraders (such as WebSocket), where the underlying HTTP connection will be taken over for @@ -529,18 +530,18 @@ transactions on those connections.

Client Object

typedef struct nng_http_client nng_http_client;
 
-

The nng_http_client object is the client side creator for nng_http objects. +

The nng_http_client object is the client side creator for nng_http objects. It is analogous to a dialer object used elsewhere in NNG, but it specifically is only for HTTP.

Create a Client

void nng_http_client_alloc(nng_http_client *clientp, const nng_url *url);
 
-

The nng_http_client_alloc allocates an HTTP client suitable for +

The nng_http_client_alloc allocates an HTTP client suitable for connecting to the server identified by url and stores a pointer to it in the location referenced by clientp.

Destroy a Client

void nng_http_client_free(nng_http_client *client);
 
-

The nng_http_client_free connection destroys the client object and any +

The nng_http_client_free connection destroys the client object and any of its resources.

@@ -554,9 +555,9 @@ and must be closed explicitly as needed.

nng_err nng_http_client_get_tls(nng_http_client *client, nng_tls_config **tlsp);
 nng_err nng_http_client_set_tls(nng_http_client *client, nng_tls_config *tls);
 
-

The nng_http_client_get_tls and nng_http_client_set_tls functions are used to +

The nng_http_client_get_tls and nng_http_client_set_tls functions are used to retrieve or change the TLS configuration used when making outbound connections, enabling -TLS as a result.

+TLS as a result.

If TLS has not been previously configured on client, then nng_http_client_get_tls will return NNG_EINVAL. Both functions will return NNG_ENOTSUP if either HTTP or TLS is not supported.

Calling nng_http_client_set_tls invalidates any client previously obtained with @@ -576,7 +577,7 @@ Existing connections will use the TLS configuration that there were created with void nng_http_client_connect(nng_http_client *client, nng_aio *aio); -

The nng_http_client_connect function makes an outgoing connection to the +

The nng_http_client_connect function makes an outgoing connection to the server configured for client, and creates an nng_http object for the connection.

This is done asynchronously, and when the operation succeseds the connection may be retried from the aio using nng_aio_get_output with index 0.

@@ -614,7 +615,7 @@ if ((rv = nng_aio_result(aio)) != 0) {

Sending the Request

void nng_http_write_request(nng_http *conn, nng_aio *aio);
 
-

The nng_http_write_request function starts an asynchronous write of +

The nng_http_write_request function starts an asynchronous write of the HTTP request associated with conn. The entire request is sent, including headers, and if present, the request body data. @@ -634,7 +635,7 @@ which provides a simpler interface for performing a complete HTTP client transac

Obtaining the Response

void nng_http_read_response(nng_http *conn, nng_aio *aio);
 
-

The nng_http_read_response function starts an asynchronous read from the +

The nng_http_read_response function starts an asynchronous read from the HTTP connection conn, reading an HTTP response into the response associated with conn, including all of the related headers.

It does not transfer any response body. To do that, use nng_http_read_all or nng_http_read.

@@ -656,9 +657,9 @@ need to do so may use the direct read functions.

Submitting the Transaction

void nng_http_transact(nng_http *conn, nng_aio *aio);
 
-

The HTTP request is issued, and the response processed, asynchronously by the nng_http_transact function. +

The HTTP request is issued, and the response processed, asynchronously by the nng_http_transact function. When the function is complete, the aio will be notified.

-

The nng_http_transact function is used to perform a complete +

The nng_http_transact function is used to perform a complete HTTP exchange over the connection conn, sending the request and attached body data to the remote server, and reading the response.

The entire response is read, including any associated body, which can @@ -699,7 +700,7 @@ may be obtained via [nng_aio_result()].

Normally the server will send any attached response, but there are circumstances where a response must be sent manually, such as when hijacking a connection.

-

In such a case, nng_http_write_response can be called, which will send the response and any attached data, asynchronously +

In such a case, nng_http_write_response can be called, which will send the response and any attached data, asynchronously using the nng_aio aio.

By default, for HTTP/1.1 connections, the connection is kept open, and will be reused to receive new requests. For HTTP/1.0, or if the client has requested diff --git a/ref/api/index.html b/ref/api/index.html index d3af95df..50e6f6f2 100644 --- a/ref/api/index.html +++ b/ref/api/index.html @@ -234,6 +234,7 @@ include the nng/nng.h header file like so:

  • Messages
  • Sockets
  • Contexts
  • +
  • Pipes
  • Memory
  • Time
  • URLs
  • diff --git a/ref/api/memory.html b/ref/api/memory.html index e41d633b..ebe675a8 100644 --- a/ref/api/memory.html +++ b/ref/api/memory.html @@ -279,7 +279,7 @@ can be used to deallocate strings allocated with - @@ -293,7 +293,7 @@ can be used to deallocate strings allocated with - diff --git a/ref/api/msg.html b/ref/api/msg.html index 4579ef41..f88303ee 100644 --- a/ref/api/msg.html +++ b/ref/api/msg.html @@ -416,7 +416,7 @@ except that they operate the message header rather than the message body.

    nng_pipe nng_msg_get_pipe(nng_msg *msg);
     void nng_msg_get_pipe(nng_msg *msg, nng_pipe p);
     
    -

    The nng_msg_set_pipe function sets the pipe associated with msg to p. +

    The nng_msg_set_pipe function sets the pipe associated with msg to p. This is most often useful when used with protocols that support directing a message to a specific peer. For example the PAIR version 1 protocol can do diff --git a/ref/api/pipe.html b/ref/api/pipe.html new file mode 100644 index 00000000..810a6292 --- /dev/null +++ b/ref/api/pipe.html @@ -0,0 +1,432 @@ + + + + + + Pipes - NNG Reference Manual (DRAFT) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

    + + + + + + + + + + + + + +
    + +
    + + + + + + + + +
    +
    + +

    Pipes

    +
    typedef struct nng_pipe_s nng_pipe;
    +
    +

    An nng_pipe is a handle to a pipe object, which can be thought of as a single connection. +(In most cases this is actually the case – the pipe is an abstraction for a single TCP or IPC connection.) +Pipes are associated with either the listener or dialer that created them, +and therefore are also automatically associated with a single socket.

    +
    +

    + + note +

    +

    The nng_pipe structure is always passed by value (both +for input parameters and return values), and should be treated opaquely. +Passing structures this way gives the compiler a chance to perform +accurate type checks in functions passing values of this type.

    +
    +
    +

    + + tip +

    +

    Most applications should never concern themselves with individual pipes. +However it is possible to access a pipe when more information about the +source of a message is needed, or when more control is required over message delivery.

    +
    +

    Pipe objects are created by dialers and and listeners.

    +

    Initialization

    +

    A pipe may be initialized using the macro NNG_PIPE_INITIALIZER +before it is opened, to prevent confusion with valid open pipes.

    +

    For example:

    +
    nng_pipe p = NNG_PIPE_INITIALIZER;
    +
    +

    Pipe Identity

    +
    int nng_pipe_id(nng_pipe p);
    +
    +

    The nng_pipe_id function returns a positive identifier for the pipe p, if it is valid. +Otherwise it returns -1.

    +
    +

    + + note +

    +

    A pipe is considered valid if it was ever created by the socket. +Pipes that are allocated on the stack or statically should be initialized with the macro +NNG_PIPE_INITIALIZER to ensure that they cannot be confused with a valid pipe.

    +
    +

    Closing a Pipe

    +
    nng_err nng_pipe_close(nng_pipe p);
    +
    +

    The nng_pipe_close function closes the supplied pipe, p. +Messages that have been submitted for sending may be flushed or delivered, +depending upon the transport.

    +

    Further attempts to use the pipe after this call returns will result in NNG_ECLOSED.

    +
    +

    + + tip +

    +

    Pipes are automatically closed when their creator closes, or when the +remote peer closes the underlying connection.

    +
    +

    Pipe Creator

    +
    nng_dialer nng_pipe_dialer(nng_pipe p);
    +nng_listener nng_pipe_listener(nng_pipe p);
    +nng_socket nng_pipe_socket(nng_pipe p);
    +
    +

    + + +These functions return the socket, dialer, or listener that created or owns the pipe.

    +

    If the pipe was does not have an associated dialer or listener, then the associated will +return [NNG_DIALER_INITIALIZER] or [NNG_LISTENER_INITIALIZER], as appropriate, and +either [nng_dialer_id] or [nng_listener_id] for the returned object will return -1.

    +
    +

    + + note +

    +

    The socket, or the endpoint, returned by these functions may be in the process of closing, +and might not be further usable as a result. (Other functions will result in NNG_ECLOSED.)

    +
    +

    Pipe Options

    +
    nng_err nng_pipe_get_bool(nng_pipe p, const char *opt, bool *valp);
    +nng_err nng_pipe_get_int(nng_pipe p, const char *opt, int *valp);
    +nng_err nng_pipe_get_ms(nng_pipe p, const char *opt, nng_duration *valp);
    +nng_err nng_pipe_get_size(nng_pipe p, const char *opt, size_t *valp);
    +nng_err nng_pipe_get_addr(nng_pipe p, const char *opt, nng_sockaddr *valp);
    +nng_err nng_pipe_get_string(nng_pipe p, const char *opt, char **valp);
    +
    +

    + + + + + +These functions are used to obtain value of an option named opt from the pipe p, and store it in the location +referenced by valp.

    +

    These functions access an option as a specific type. The transport layer will have details about which options +are available, and which type they may be accessed using.

    +

    In the case of nng_pipe_get_string, the string is created as if by nng_strdup, and must be freed by +the caller using nng_strfree when no longer needed.

    +

    Pipe Notifications

    +
    typedef enum {
    +        NNG_PIPE_EV_ADD_PRE,
    +        NNG_PIPE_EV_ADD_POST,
    +        NNG_PIPE_EV_REM_POST,
    +} nng_pipe_ev;
    +
    +typedef void (*nng_pipe_cb)(nng_pipe, nng_pipe_ev, void *);
    +
    +nng_err nng_pipe_notify(nng_socket s, nng_pipe_ev ev, nng_pipe_cb cb, void *arg);
    +
    +

    The nng_pipe_notify function registers the callback function cb +to be called whenever the pipe event specified by +ev occurs on the socket s. +The callback cb will be passed arg as its final argument.

    +

    A different callback may be supplied for each event. +Each event may have at most one callback registered. +Registering a callback implicitly unregisters any previously registered.

    +

    The following pipe events are supported:

    +
    + + + +
    EventDescription
    NNG_PIPE_EV_ADD_PREThis event occurs after a connection and negotiation has completed, but before the pipe is added to the socket. If the pipe is closed (using nng_pipe_close) at this point, the socket will never see the pipe, and no further events will occur for the given pipe.
    NNG_PIPE_EV_ADD_POSTThis event occurs after the pipe is fully added to the socket. Prior to this time, it is not possible to communicate over the pipe with the socket.
    NNG_PIPE_EV_REM_POSTThis event occurs after the pipe has been removed from the socket. The underlying transport may be closed at this point, and it is not possible communicate using this pipe.
    +
    +

    + + warning +

    +

    The callback cb function must not attempt to perform any +accesses to the socket, as it is called with a lock on the socket held! +Doing so would thus result in a deadlock.

    +
    +
    +

    + + tip +

    +

    The callback cb may close a pipe for any reason by simply closing it using nng_pipe_close. +For example, this might be done to prevent an unauthorized peer from connecting to the socket, +if an authorization check made during NNG_PIPE_EV_ADD_PRE fails.

    +
    +
    +

    + + note +

    +

    This function ignores invalid values for ev.

    +
    + + + + + + + +
    + + +
    +
    + + + +
    + + + + + + + + + + + + + + + + + + + +
    + + diff --git a/ref/api/sock.html b/ref/api/sock.html index da25cd62..2f9127ed 100644 --- a/ref/api/sock.html +++ b/ref/api/sock.html @@ -340,7 +340,7 @@ a result of NNG_ECLOSED. note

    Closing a socket also invalidates any dialers, listeners, -pipes, or contexts associated with it.

    +pipes, or contexts associated with it.

    diff --git a/ref/api/stream.html b/ref/api/stream.html index fb6770a7..8b7abc6c 100644 --- a/ref/api/stream.html +++ b/ref/api/stream.html @@ -244,7 +244,7 @@ using these Streams APIs.

    note

    The nng_stream object is used for raw byte stream connections, and -should not be confused with a pipe object created on a socket using +should not be confused with a pipe object created on a socket using the nng_listen, nng_dial or related functions.

    Sending and Receiving Data

    -- cgit v1.2.3-70-g09d2