Skip to content

Commit

Permalink
Several minor cleanups. Fix socket id stat for listener.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Jul 10, 2021
1 parent 2574efb commit 16597cc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 31 deletions.
8 changes: 4 additions & 4 deletions src/core/dialer.c
@@ -1,5 +1,5 @@
//
// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Devolutions <info@devolutions.net>
//
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions src/core/listener.c
@@ -1,5 +1,5 @@
//
// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Devolutions <info@devolutions.net>
//
Expand Down Expand Up @@ -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);
}
Expand Down
19 changes: 5 additions & 14 deletions src/core/protocol.h
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
16 changes: 6 additions & 10 deletions src/core/socket.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 16597cc

Please sign in to comment.