From 16597cc81cc9fbdfd15349be1b0bd57fb9392241 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 9 Jul 2021 20:41:28 -0700 Subject: [PATCH] Several minor cleanups. Fix socket id stat for listener. --- src/core/dialer.c | 8 ++++---- src/core/listener.c | 7 ++++--- src/core/protocol.h | 19 +++++-------------- src/core/socket.c | 16 ++++++---------- 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/core/dialer.c b/src/core/dialer.c index 00d2c1635..3044f2b82 100644 --- a/src/core/dialer.c +++ b/src/core/dialer.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2018 Devolutions // @@ -179,9 +179,9 @@ dialer_stats_init(nni_dialer *d) dialer_stat_init(d, &d->st_oom, &oom_info); dialer_stat_init(d, &d->st_reject, &reject_info); - nni_stat_set_id(&d->st_root, d->d_id); - nni_stat_set_id(&d->st_id, d->d_id); - nni_stat_set_id(&d->st_sock, nni_sock_id(d->d_sock)); + nni_stat_set_id(&d->st_root, (int) d->d_id); + nni_stat_set_id(&d->st_id, (int) d->d_id); + nni_stat_set_id(&d->st_sock, (int) nni_sock_id(d->d_sock)); nni_stat_set_string(&d->st_url, d->d_url->u_rawurl); nni_stat_register(&d->st_root); } diff --git a/src/core/listener.c b/src/core/listener.c index 32aa65ed6..ebe1f416e 100644 --- a/src/core/listener.c +++ b/src/core/listener.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2018 Devolutions // @@ -173,8 +173,9 @@ listener_stats_init(nni_listener *l) listener_stat_init(l, &l->st_oom, &oom_info); listener_stat_init(l, &l->st_reject, &reject_info); - nni_stat_set_id(&l->st_root, l->l_id); - nni_stat_set_id(&l->st_id, l->l_id); + nni_stat_set_id(&l->st_root, (int) l->l_id); + nni_stat_set_id(&l->st_id, (int) l->l_id); + nni_stat_set_id(&l->st_sock, (int) nni_sock_id(l->l_sock)); nni_stat_set_string(&l->st_url, l->l_url->u_rawurl); nni_stat_register(&l->st_root); } diff --git a/src/core/protocol.h b/src/core/protocol.h index 14fcde754..79296cdfe 100644 --- a/src/core/protocol.h +++ b/src/core/protocol.h @@ -74,14 +74,6 @@ struct nni_proto_ctx_ops { // ctx_send is an asynchronous send. void (*ctx_send)(void *, nni_aio *); - // ctx_drain drains the context, signaling the aio when done. - // This should prevent any further receives from completing, - // and only sends that had already been submitted should be - // permitted to continue. It may be NULL for protocols where - // draining without an ability to receive makes no sense - // (e.g. REQ or SURVEY). - void (*ctx_drain)(void *, nni_aio *); - // ctx_options array. nni_option *ctx_options; }; @@ -152,9 +144,8 @@ struct nni_proto { // during the life of the project. If we add a new version, please keep // the old version around -- it may be possible to automatically convert // older versions in the future. -#define NNI_PROTOCOL_V0 0x50520000u // "pr\0\0" -#define NNI_PROTOCOL_V1 0x50520001u // "pr\0\1" -#define NNI_PROTOCOL_VERSION NNI_PROTOCOL_V1 +#define NNI_PROTOCOL_V2 0x50520002u // "pr\0\2" +#define NNI_PROTOCOL_VERSION NNI_PROTOCOL_V2 // These flags determine which operations make sense. We use them so that // we can reject attempts to create notification fds for operations that make @@ -167,14 +158,14 @@ struct nni_proto { // nni_proto_open is called by the protocol to create a socket instance // with its ops vector. The intent is that applications will only see -// the single protocol-specific constructure, like nng_pair_v0_open(), +// the single protocol-specific constructor, like nng_pair_v0_open(), // which should just be a thin wrapper around this. If the protocol has // not been initialized yet, this routine will do so. extern int nni_proto_open(nng_socket *, const nni_proto *); -// Protocol numbers. These are to be used with nng_socket_create(). +// Protocol numbers. // These values are used on the wire, so must not be changed. The major -// number of the protocol is shifted left by 4 bits, and a subprotocol is +// number of the protocol is shifted left by 4 bits, and a sub-protocol is // assigned in the lower 4 bits. // // There are gaps in the list, which are obsolete or unsupported protocols. diff --git a/src/core/socket.c b/src/core/socket.c index 16476be10..e170289d6 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -124,15 +124,10 @@ sock_get_fd(void *s, unsigned flag, int *fdp) return (NNG_ENOTSUP); } - switch (flag) { - case NNI_PROTO_FLAG_SND: + if (flag == NNI_PROTO_FLAG_SND) { rv = nni_msgq_get_sendable(SOCK(s)->s_uwq, &p); - break; - case NNI_PROTO_FLAG_RCV: + } else { rv = nni_msgq_get_recvable(SOCK(s)->s_urq, &p); - break; - default: - return (NNG_EINVAL); } if (rv == 0) { @@ -499,7 +494,7 @@ sock_stats_init(nni_sock *s) sock_stat_init(s, &s->st_tx_bytes, &tx_bytes_info); sock_stat_init(s, &s->st_rx_bytes, &rx_bytes_info); - nni_stat_set_id(&s->st_id, s->s_id); + nni_stat_set_id(&s->st_id, (int) s->s_id); nni_stat_set_string(&s->st_name, s->s_name); nni_stat_set_string(&s->st_protocol, nni_sock_proto_name(s)); } @@ -668,7 +663,7 @@ nni_sock_open(nni_sock **sockp, const nni_proto *proto) #ifdef NNG_ENABLE_STATS // Set up basic stat values. - nni_stat_set_id(&s->st_id, s->s_id); + nni_stat_set_id(&s->st_id, (int) s->s_id); // Add our stats chain. nni_stat_register(&s->st_root); @@ -1478,7 +1473,8 @@ dialer_timer_start_locked(nni_dialer *d) // This algorithm may lead to slight biases because we don't // have a statistically perfect distribution with the modulo of // the random number, but this really doesn't matter. - nni_sleep_aio(back_off ? nni_random() % back_off : 0, &d->d_tmo_aio); + nni_sleep_aio( + back_off ? (int) nni_random() % back_off : 0, &d->d_tmo_aio); } void