diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-12-29 21:28:49 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-12-31 17:10:04 -0800 |
| commit | a73ff5363eae228009413872b05aff758a46c5ca (patch) | |
| tree | d5fa805188f915fc94c9b80d4f5cbbb96e6a4551 /src/supplemental/websocket | |
| parent | e0fff1f9c45f5486fc2e7eeb49b4462c3bb2dad4 (diff) | |
| download | nng-a73ff5363eae228009413872b05aff758a46c5ca.tar.gz nng-a73ff5363eae228009413872b05aff758a46c5ca.tar.bz2 nng-a73ff5363eae228009413872b05aff758a46c5ca.zip | |
fixes #825 TCP public API should use generic setopt/getopt
This changes much of the internal API for TCP option handling, and
includes hooks for some of this in various consumers. Note that the
consumers still need to have additional work done to complete them,
which will be part of providing public "raw" TLS and WebSocket APIs.
We would also like to finish addressing the call sites of
nni_tcp_listener_start() that assume the sockaddr is modified --
it would be superior to use the NNG_OPT_LOCADDR option. Thaat will be
addressed in a follow up PR.
Diffstat (limited to 'src/supplemental/websocket')
| -rw-r--r-- | src/supplemental/websocket/websocket.c | 55 | ||||
| -rw-r--r-- | src/supplemental/websocket/websocket.h | 23 |
2 files changed, 39 insertions, 39 deletions
diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c index c214e6d7..3d3a68cb 100644 --- a/src/supplemental/websocket/websocket.c +++ b/src/supplemental/websocket/websocket.c @@ -1,6 +1,7 @@ // // Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> +// Copyright 2018 Devolutions <info@devolutions.net> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -698,22 +699,45 @@ ws_send_control(nni_ws *ws, uint8_t op, uint8_t *buf, size_t len) ws_start_write(ws); } +static const nni_option ws_options[] = { + { + .o_name = NULL, + }, +}; + int -nni_ws_sock_addr(nni_ws *ws, nni_sockaddr *sa) +nni_ws_getopt(nni_ws *ws, const char *name, void *buf, size_t *szp, nni_type t) { int rv; + nni_mtx_lock(&ws->mtx); - rv = ws->closed ? NNG_ECLOSED : nni_http_sock_addr(ws->http, sa); + if (ws->closed) { + nni_mtx_unlock(&ws->mtx); + return (NNG_ECLOSED); + } + rv = nni_http_conn_getopt(ws->http, name, buf, szp, t); + if (rv == NNG_ENOTSUP) { + rv = nni_getopt(ws_options, name, ws, buf, szp, t); + } nni_mtx_unlock(&ws->mtx); return (rv); } int -nni_ws_peer_addr(nni_ws *ws, nni_sockaddr *sa) +nni_ws_setopt( + nni_ws *ws, const char *name, const void *buf, size_t sz, nni_type t) { int rv; + nni_mtx_lock(&ws->mtx); - rv = ws->closed ? NNG_ECLOSED : nni_http_peer_addr(ws->http, sa); + if (ws->closed) { + nni_mtx_unlock(&ws->mtx); + return (NNG_ECLOSED); + } + rv = nni_http_conn_setopt(ws->http, name, buf, sz, t); + if (rv == NNG_ENOTSUP) { + rv = nni_setopt(ws_options, name, ws, buf, sz, t); + } nni_mtx_unlock(&ws->mtx); return (rv); } @@ -1098,18 +1122,6 @@ nni_ws_close(nni_ws *ws) nni_ws_close_error(ws, WS_CLOSE_NORMAL_CLOSE); } -nni_http_res * -nni_ws_response(nni_ws *ws) -{ - return (ws->res); -} - -nni_http_req * -nni_ws_request(nni_ws *ws) -{ - return (ws->req); -} - const char * nni_ws_request_headers(nni_ws *ws) { @@ -1132,17 +1144,6 @@ nni_ws_response_headers(nni_ws *ws) return (ws->reshdrs); } -bool -nni_ws_tls_verified(nni_ws *ws) -{ - bool rv; - - nni_mtx_lock(&ws->mtx); - rv = nni_http_tls_verified(ws->http); - nni_mtx_unlock(&ws->mtx); - return (rv); -} - static void ws_fini(void *arg) { diff --git a/src/supplemental/websocket/websocket.h b/src/supplemental/websocket/websocket.h index 9936b10f..88b4bfb4 100644 --- a/src/supplemental/websocket/websocket.h +++ b/src/supplemental/websocket/websocket.h @@ -1,6 +1,7 @@ // // Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> +// Copyright 2018 Devolutions <info@devolutions.net> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -52,18 +53,16 @@ extern int nni_ws_dialer_get_tls(nni_ws_dialer *, nng_tls_config **); // not confirm the server's response at the HTTP level. (It can still issue // a websocket close). -extern void nni_ws_send_msg(nni_ws *, nng_aio *); -extern void nni_ws_recv_msg(nni_ws *, nng_aio *); -extern nng_http_res *nni_ws_response(nni_ws *); -extern nng_http_req *nni_ws_request(nni_ws *); -extern int nni_ws_sock_addr(nni_ws *, nni_sockaddr *); -extern int nni_ws_peer_addr(nni_ws *, nni_sockaddr *); -extern void nni_ws_close(nni_ws *); -extern void nni_ws_close_error(nni_ws *, uint16_t); -extern void nni_ws_fini(nni_ws *); -extern const char * nni_ws_response_headers(nni_ws *); -extern const char * nni_ws_request_headers(nni_ws *); -extern bool nni_ws_tls_verified(nni_ws *); +extern void nni_ws_send_msg(nni_ws *, nng_aio *); +extern void nni_ws_recv_msg(nni_ws *, nng_aio *); +extern void nni_ws_close(nni_ws *); +extern void nni_ws_close_error(nni_ws *, uint16_t); +extern void nni_ws_fini(nni_ws *); +extern const char *nni_ws_response_headers(nni_ws *); +extern const char *nni_ws_request_headers(nni_ws *); +extern int nni_ws_getopt(nni_ws *, const char *, void *, size_t *, nni_type); +extern int nni_ws_setopt( + nni_ws *, const char *, const void *, size_t, nni_type); // The implementation will send periodic PINGs, and respond with PONGs. |
