diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-07-02 22:36:08 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-07-03 19:00:19 -0700 |
| commit | d1a9c84a6b375cb25a8b7475957130e364b41753 (patch) | |
| tree | 5444721d96a84d92e3ed258b4d51f80adf6b200c /src/transport/tls | |
| parent | a772bcc6ebe198f939889abbda18eded2a326941 (diff) | |
| download | nng-d1a9c84a6b375cb25a8b7475957130e364b41753.tar.gz nng-d1a9c84a6b375cb25a8b7475957130e364b41753.tar.bz2 nng-d1a9c84a6b375cb25a8b7475957130e364b41753.zip | |
fixes #572 Several locking errors found
fixes #573 atomic flags could help
This introduces a new atomic flag, and reduces some of the global
locking. The lock refactoring work is not yet complete, but this is
a positive step forward, and should help with certain things.
While here we also fixed a compile warning due to incorrect types.
Diffstat (limited to 'src/transport/tls')
| -rw-r--r-- | src/transport/tls/tls.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/transport/tls/tls.c b/src/transport/tls/tls.c index b4f555da..5e1a1e8d 100644 --- a/src/transport/tls/tls.c +++ b/src/transport/tls/tls.c @@ -877,7 +877,11 @@ static int tls_ep_get_nodelay(void *arg, void *v, size_t *szp, nni_opt_type t) { tls_ep *ep = arg; - return (nni_copyout_bool(ep->nodelay, v, szp, t)); + int rv; + nni_mtx_lock(&ep->mtx); + rv = nni_copyout_bool(ep->nodelay, v, szp, t); + nni_mtx_unlock(&ep->mtx); + return (rv); } static int @@ -898,7 +902,11 @@ static int tls_ep_get_keepalive(void *arg, void *v, size_t *szp, nni_opt_type t) { tls_ep *ep = arg; - return (nni_copyout_bool(ep->keepalive, v, szp, t)); + int rv; + nni_mtx_lock(&ep->mtx); + rv = nni_copyout_bool(ep->keepalive, v, szp, t); + nni_mtx_unlock(&ep->mtx); + return (rv); } static int @@ -947,7 +955,11 @@ static int tls_ep_get_recvmaxsz(void *arg, void *v, size_t *szp, nni_opt_type t) { tls_ep *ep = arg; - return (nni_copyout_size(ep->rcvmax, v, szp, t)); + int rv; + nni_mtx_lock(&ep->mtx); + rv = nni_copyout_size(ep->rcvmax, v, szp, t); + nni_mtx_unlock(&ep->mtx); + return (rv); } static int @@ -974,9 +986,11 @@ tls_ep_set_config(void *arg, const void *data, size_t sz, nni_opt_type t) if (cfg == NULL) { return (NNG_EINVAL); } + nni_mtx_lock(&ep->mtx); old = ep->cfg; nni_tls_config_hold(cfg); ep->cfg = cfg; + nni_mtx_unlock(&ep->mtx); if (old != NULL) { nni_tls_config_fini(old); } @@ -987,7 +1001,11 @@ static int tls_ep_get_config(void *arg, void *v, size_t *szp, nni_opt_type t) { tls_ep *ep = arg; - return (nni_copyout_ptr(ep->cfg, v, szp, t)); + int rv; + nni_mtx_lock(&ep->mtx); + rv = nni_copyout_ptr(ep->cfg, v, szp, t); + nni_mtx_unlock(&ep->mtx); + return (rv); } static int @@ -1055,7 +1073,9 @@ tls_ep_set_cert_key_file(void *arg, const void *v, size_t sz, nni_opt_type t) int rv; if ((rv = tls_ep_chk_string(v, sz, t)) == 0) { + nni_mtx_lock(&ep->mtx); rv = nng_tls_config_cert_key_file(ep->cfg, v, NULL); + nni_mtx_unlock(&ep->mtx); } return (rv); } |
