diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-06-12 20:05:34 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-06-13 18:01:52 -0700 |
| commit | da2aac4a6eb10af88e3938068e24c58aea1832b1 (patch) | |
| tree | fb0676be5426ed1510945b7e7fe3d09eb45333a7 /src/core/transport.h | |
| parent | 61ffae5e3649897776c26799ccaaa35d578ba816 (diff) | |
| download | nng-da2aac4a6eb10af88e3938068e24c58aea1832b1.tar.gz nng-da2aac4a6eb10af88e3938068e24c58aea1832b1.tar.bz2 nng-da2aac4a6eb10af88e3938068e24c58aea1832b1.zip | |
fixes #540 nni_ep_opttype serves no purpose
fixes #538 setopt should have an explicit chkopt routine
fixes #537 Internal TCP API needs better name separation
fixes #524 Option types should be "typed"
This is a rework of the option management code, to make it both clearer
and to prepare for further work to break up endpoints. This reduces
a certain amount of dead or redundant code, and actually saves cycles
when setting options, as some loops were not terminated that should have
been.
Diffstat (limited to 'src/core/transport.h')
| -rw-r--r-- | src/core/transport.h | 134 |
1 files changed, 64 insertions, 70 deletions
diff --git a/src/core/transport.h b/src/core/transport.h index 1046901c..e45aa7ec 100644 --- a/src/core/transport.h +++ b/src/core/transport.h @@ -47,39 +47,44 @@ struct nni_tran { // older versions in the future. #define NNI_TRANSPORT_V0 0x54520000 #define NNI_TRANSPORT_V1 0x54520001 -#define NNI_TRANSPORT_VERSION NNI_TRANSPORT_V1 +#define NNI_TRANSPORT_V2 0x54520002 +#define NNI_TRANSPORT_VERSION NNI_TRANSPORT_V2 -// Endpoint option handlers. -struct nni_tran_ep_option { - // eo_name is the name of the option. - const char *eo_name; +// Option handlers. +struct nni_tran_option { + // o_name is the name of the option. + const char *o_name; - // eo_type is the type of the option. - int eo_type; + // o_type is the type of the option. + nni_opt_type o_type; - // eo_getopt retrieves the value of the option. - int (*eo_getopt)(void *, void *, size_t *, int); + // o_get retrieves the value of the option. The first argument is the + // dialer, listener, or pipe where the request is being made. + int (*o_get)(void *, void *, size_t *, nni_opt_type); - // eo_set sets the value of the option. If the first argument - // (the endpoint) is NULL, then no actual set operation should be - // performed, but the option should be sanity tested for presence - // and size. (This permits the core to validate that an option - // is reasonable and be set even before endpoints are created.) - int (*eo_setopt)(void *, const void *, size_t, int); + // o_set sets the value of the option. The first argument is the + // dialer, listener, or pipe where the request is being made. + int (*o_set)(void *, const void *, size_t, nni_opt_type); + + // o_chk checks to see if the proposed value is legal -- this is + // checks only the type, size, and generic range validation. This + // function can be called before any transport objects are created. + int (*o_chk)(const void *, size_t, nni_opt_type); }; -// Endpoint operations are called by the socket in a protocol-independent -// fashion. The socket makes individual calls, which are expected to block -// if appropriate (except for destroy), or run asynchronously if an aio -// is provided. Endpoints are unable to call back into the socket, to prevent -// recusive entry and deadlock. +// Endpoint operations are called by the socket in a +// protocol-independent fashion. The socket makes individual calls, +// which are expected to block if appropriate (except for destroy), or +// run asynchronously if an aio is provided. Endpoints are unable to +// call back into the socket, to prevent recusive entry and deadlock. // // For a given endpoint, the framework holds a lock so that each entry // point is run exclusively of the others. (Transports must still guard // against any asynchronous operations they manage themselves, though.) struct nni_tran_ep_ops { // ep_init creates a vanilla endpoint. The value created is - // used for the first argument for all other endpoint functions. + // used for the first argument for all other endpoint + // functions. int (*ep_init)(void **, nni_url *, nni_sock *, int); // ep_fini frees the resources associated with the endpoint. @@ -87,8 +92,8 @@ struct nni_tran_ep_ops { void (*ep_fini)(void *); // ep_connect establishes a connection. It can return errors - // NNG_EACCESS, NNG_ECONNREFUSED, NNG_EBADADDR, NNG_ECONNFAILED, - // NNG_ETIMEDOUT, and NNG_EPROTO. + // NNG_EACCESS, NNG_ECONNREFUSED, NNG_EBADADDR, + // NNG_ECONNFAILED, NNG_ETIMEDOUT, and NNG_EPROTO. void (*ep_connect)(void *, nni_aio *); // ep_bind just does the bind() and listen() work, @@ -101,45 +106,34 @@ struct nni_tran_ep_ops { // ep_accept accepts an inbound connection. void (*ep_accept)(void *, nni_aio *); - // ep_close stops the endpoint from operating altogether. It does - // not affect pipes that have already been created. It is nonblocking. + // ep_close stops the endpoint from operating altogether. It + // does not affect pipes that have already been created. It is + // nonblocking. void (*ep_close)(void *); - // ep_options is an array of endpoint options. The final element must - // have a NULL name. If this member is NULL, then no transport specific - // options are available. - nni_tran_ep_option *ep_options; -}; - -// Pipe option handlers. We only have get for pipes; once a pipe is created -// no options may be set on it. -struct nni_tran_pipe_option { - // po_name is the name of the option. - const char *po_name; - - // po_type is the type of the option. - int po_type; - - // po_getopt retrieves the value of the option. - int (*po_getopt)(void *, void *, size_t *, int); + // ep_options is an array of endpoint options. The final + // element must have a NULL name. If this member is NULL, then + // no transport specific options are available. + nni_tran_option *ep_options; }; -// Pipe operations are entry points called by the socket. These may be called -// with socket locks held, so it is forbidden for the transport to call -// back into the socket at this point. (Which is one reason pointers back -// to socket or even enclosing pipe state, are not provided.) +// Pipe operations are entry points called by the socket. These may be +// called with socket locks held, so it is forbidden for the transport +// to call back into the socket at this point. (Which is one reason +// pointers back to socket or even enclosing pipe state, are not +// provided.) struct nni_tran_pipe_ops { // 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. + // 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. void (*p_fini)(void *); // p_start starts the pipe running. This gives the transport a - // chance to hook into any transport specific negotiation phase. - // The pipe will not have its p_send or p_recv calls started, and - // will not be access by the "socket" until the pipe has indicated - // its readiness by finishing the aio. + // chance to hook into any transport specific negotiation + // phase. The pipe will not have its p_send or p_recv calls + // started, and will not be access by the "socket" until the + // pipe has indicated its readiness by finishing the aio. void (*p_start)(void *, nni_aio *); // p_stop stops the pipe, waiting for any callbacks that are @@ -147,31 +141,31 @@ struct nni_tran_pipe_ops { // resources with p_fini. void (*p_stop)(void *); - // p_aio_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 again. The transport will - // have the responsibility to free the message (nng_msg_free()) when - // it is finished with it. + // p_aio_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 + // again. The transport will have the responsibility to free + // the message (nng_msg_free()) when it is finished with it. void (*p_send)(void *, nni_aio *); - // p_recv schedules a message receive. This will be performed even for - // cases where no data is expected, to allow detection of a remote - // disconnect. + // p_recv schedules a message receive. This will be performed + // even for cases where no data is expected, to allow detection + // of a remote disconnect. void (*p_recv)(void *, nni_aio *); - // p_close closes the pipe. Further recv or send operations should - // return back NNG_ECLOSED. + // p_close closes the pipe. Further recv or send operations + // should return back NNG_ECLOSED. void (*p_close)(void *); - // p_peer returns the peer protocol. This may arrive in whatever - // transport specific manner is appropriate. + // p_peer returns the peer protocol. This may arrive in + // whatever transport specific manner is appropriate. uint16_t (*p_peer)(void *); - // p_options is an array of pipe options. The final element must have - // a NULL name. If this member is NULL, then no transport specific - // options are available. - nni_tran_pipe_option *p_options; + // p_options is an array of pipe options. The final element + // must have a NULL name. If this member is NULL, then no + // transport specific options are available. + nni_tran_option *p_options; }; // These APIs are used by the framework internally, and not for use by |
