diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-12-07 22:28:15 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-12-08 14:02:42 -0800 |
| commit | d6ab6bca7a538c1a320ce00ab845e98c16649c94 (patch) | |
| tree | d4a8a4f8ac49eee54c2d9bbdf8f9da6c28362311 /src/sp | |
| parent | 5223a142e38a320ce53097cea450d8ba7f175193 (diff) | |
| download | nng-d6ab6bca7a538c1a320ce00ab845e98c16649c94.tar.gz nng-d6ab6bca7a538c1a320ce00ab845e98c16649c94.tar.bz2 nng-d6ab6bca7a538c1a320ce00ab845e98c16649c94.zip | |
pipes and endpoints: support for inline allocations of transport data
This is a new transport API, which should make it easier for transports
to rely upon lifetime guarantees made by the common SP framework, thus
eliminating the need for transport specific reference counters, reap
lists, and similar.
The transport declares the size of the object in the ops vector (for
pipe, dialer, or listener), and the framework supplies one allocated
using the associated allocator.
For now these add the pipe object to the socket and endpoint using
linked linked lists. The plan is to transition those to reference
counts which should be lighter weight and free form locking issues.
The pipe teardown has been moved more fully to the reaper, to avoid
some of the deadlocks that can occur as nni_pipe_close can be called
from almost any context.
For now the old API is retained as well, but the intention is to convert
all the transports and then remove it.
Diffstat (limited to 'src/sp')
| -rw-r--r-- | src/sp/transport.h | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/sp/transport.h b/src/sp/transport.h index b7134595..10207f28 100644 --- a/src/sp/transport.h +++ b/src/sp/transport.h @@ -12,6 +12,7 @@ #ifndef PROTOCOL_SP_TRANSPORT_H #define PROTOCOL_SP_TRANSPORT_H +#include "core/defs.h" #include "core/options.h" // Endpoint operations are called by the socket in a @@ -25,6 +26,10 @@ // against any asynchronous operations they manage themselves, though.) struct nni_sp_dialer_ops { + // d_size is the size of transport specific data allocated + // to the listener. + size_t d_size; + // d_init creates a vanilla dialer. The value created is // used for the first argument for all other dialer functions. int (*d_init)(void **, nng_url *, nni_dialer *); @@ -64,6 +69,10 @@ struct nni_sp_dialer_ops { }; struct nni_sp_listener_ops { + // l_size is the size of transport specific data allocated + // to the listener. + size_t l_size; + // l_init creates a vanilla listener. The value created is // used for the first argument for all other listener functions. int (*l_init)(void **, nng_url *, nni_listener *); @@ -121,20 +130,27 @@ struct nni_sp_pipe_ops { // p_init initializes the pipe data structures. The main // purpose of this is so that the pipe will see the upper // layer nni_pipe and get a chance to register stats and such. + size_t p_size; + + // p_init initializes the transport's pipe data structure. + // The pipe MUST be left in a state that p_fini can be safely + // called on it, even if it does not succeed. (The upper layers + // will call p_fini as part of the cleanup of a failure.) + // This function should not acquire any locks. int (*p_init)(void *, nni_pipe *); // p_fini destroys the pipe. This should clean up all local // resources, including closing files and freeing memory, used // by the pipe. After this call returns, the system will not - // make further calls on the same pipe. + // make further calls on the same pipe. This call should not block. void (*p_fini)(void *); // p_stop stops the pipe, waiting for any callbacks that are // outstanding to complete. This is done before tearing down - // resources with p_fini. + // resources with p_fini. Unlike p_fini, p_stop may block. void (*p_stop)(void *); - // p_aio_send queues the message for transmit. If this fails, + // p_send queues the message for transmit. If this fails, // then the caller may try again with the same message (or free // it). If the call succeeds, then the transport has taken // ownership of the message, and the caller may not use it |
