From 1eaf9e86a8f54d77d6f392829d1b859c94965329 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 5 Jan 2020 11:16:03 -0800 Subject: fixes #1112 POSIX pollq finalizers could be simpler We reap the connections when closing, to ensure that the clean up is done outside the pollq thread. This also reduces pressure on the pollq, we think. But more importantly it eliminates some complex code that was meant to avoid deadlocks, but ultimately created other use-after-free challenges. This work is an enabler for further simplifications in the aio/task logic. While here we converted some potentially racy locking of the dialers and reference counts to simpler lock-free reference counting. --- src/platform/posix/posix_tcp.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/platform/posix/posix_tcp.h') diff --git a/src/platform/posix/posix_tcp.h b/src/platform/posix/posix_tcp.h index e1a70bc3..87312dff 100644 --- a/src/platform/posix/posix_tcp.h +++ b/src/platform/posix/posix_tcp.h @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. +// Copyright 2020 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2018 Devolutions // @@ -27,7 +27,21 @@ struct nni_tcp_conn { nni_tcp_dialer *dialer; nni_reap_item reap; }; -extern int nni_posix_tcp_init(nni_tcp_conn **, nni_posix_pfd *); + +struct nni_tcp_dialer { + nni_list connq; // pending connections + bool closed; + bool nodelay; + bool keepalive; + struct sockaddr_storage src; + size_t srclen; + nni_mtx mtx; + nni_atomic_u64 ref; + nni_atomic_bool fini; +}; + +extern int nni_posix_tcp_alloc(nni_tcp_conn **, nni_tcp_dialer *); +extern void nni_posix_tcp_init(nni_tcp_conn *, nni_posix_pfd *); extern void nni_posix_tcp_start(nni_tcp_conn *, int, int); extern void nni_posix_tcp_dialer_rele(nni_tcp_dialer *); -- cgit v1.2.3-70-g09d2