From 64e784237d143aa032311942bc44abd22e1e4114 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 18 Feb 2019 20:15:16 -0800 Subject: fixes #848 server hang waiting for client handshake fixes #698 Need TCP stats fixes #699 Need IPC stats fixes #701 Need TLS stats This commit addresses a problem when negotiating using one of the stream based negotiation APIs -- a slow or misbehaving peer can prevent well behaved ones from establishing a connection. The fix is a fairly significant change in how these transports link up, and it does rely on the fact that the socket only has a single accept() or connect() pending at a time (on a given endpoint that is). While here, we have completely revamped the way transport statistics are done, offering a standard API for collecting these statistics. Unfortunately, this completely borks the statistics for inproc. As we are planning to change the way inproc works soon, in order to provide more control and work on performance fixes for the message queue, we feel this is an acceptable trade-off. Furthermore, almost nobody uses inproc for anything, and even fewer people are making use of the statistics at this time. --- src/core/pipe.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/core/pipe.c') diff --git a/src/core/pipe.c b/src/core/pipe.c index 6ad62fa4..44957def 100644 --- a/src/core/pipe.c +++ b/src/core/pipe.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2019 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2018 Devolutions // @@ -228,6 +228,18 @@ pipe_create(nni_pipe **pp, nni_sock *sock, nni_tran *tran, void *tdata) nni_stat_init_id(&st->s_sock_id, "socket", "socket for pipe", nni_sock_id(p->p_sock)); nni_stat_append(&st->s_root, &st->s_sock_id); + nni_stat_init_atomic(&st->s_rxmsgs, "rxmsgs", "messages received"); + nni_stat_set_unit(&st->s_rxmsgs, NNG_UNIT_MESSAGES); + nni_stat_append(&st->s_root, &st->s_rxmsgs); + nni_stat_init_atomic(&st->s_txmsgs, "txmsgs", "messages sent"); + nni_stat_set_unit(&st->s_txmsgs, NNG_UNIT_MESSAGES); + nni_stat_append(&st->s_root, &st->s_txmsgs); + nni_stat_init_atomic(&st->s_rxbytes, "rxbytes", "bytes received"); + nni_stat_set_unit(&st->s_rxbytes, NNG_UNIT_BYTES); + nni_stat_append(&st->s_root, &st->s_rxbytes); + nni_stat_init_atomic(&st->s_txbytes, "txbytes", "bytes sent"); + nni_stat_set_unit(&st->s_txbytes, NNG_UNIT_BYTES); + nni_stat_append(&st->s_root, &st->s_txbytes); if ((rv != 0) || ((rv = p->p_tran_ops.p_init(tdata, p)) != 0) || ((rv = pops->pipe_init(&p->p_proto_data, p, sdata)) != 0)) { @@ -337,3 +349,27 @@ nni_pipe_add_stat(nni_pipe *p, nni_stat_item *item) { nni_stat_append(&p->p_stats.s_root, item); } + +void +nni_pipe_bump_rx(nni_pipe *p, size_t nbytes) +{ + nni_stat_inc_atomic(&p->p_stats.s_rxbytes, nbytes); + nni_stat_inc_atomic(&p->p_stats.s_rxmsgs, 1); +} + +void +nni_pipe_bump_tx(nni_pipe *p, size_t nbytes) +{ + nni_stat_inc_atomic(&p->p_stats.s_txbytes, nbytes); + nni_stat_inc_atomic(&p->p_stats.s_txmsgs, 1); +} + +void +nni_pipe_bump_error(nni_pipe *p, int err) +{ + if (p->p_dialer != NULL) { + nni_dialer_bump_error(p->p_dialer, err); + } else { + nni_listener_bump_error(p->p_listener, err); + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2