diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-08-27 11:14:33 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-08-27 15:33:29 -0700 |
| commit | de8aca84eba4f52741fd49d1a57d1fe20a2ec7f5 (patch) | |
| tree | 32ceb0fb7da277c9ac45529afd06b84edba5c35a /src/supplemental/websocket/websocket.c | |
| parent | 84a1e7455c158441dd7b33d2eb296cc33dd5a6df (diff) | |
| download | nng-de8aca84eba4f52741fd49d1a57d1fe20a2ec7f5.tar.gz nng-de8aca84eba4f52741fd49d1a57d1fe20a2ec7f5.tar.bz2 nng-de8aca84eba4f52741fd49d1a57d1fe20a2ec7f5.zip | |
fixes #673 transports could benefit from access to upper layer
Diffstat (limited to 'src/supplemental/websocket/websocket.c')
| -rw-r--r-- | src/supplemental/websocket/websocket.c | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c index a1553704..f0a1a269 100644 --- a/src/supplemental/websocket/websocket.c +++ b/src/supplemental/websocket/websocket.c @@ -32,7 +32,7 @@ typedef struct ws_header { struct nni_ws { nni_list_node node; nni_reap_item reap; - int mode; // NNI_EP_MODE_DIAL or NNI_EP_MODE_LISTEN + bool server; bool closed; bool ready; bool wclose; @@ -296,10 +296,10 @@ ws_msg_init_control( frame->buf = frame->sdata; frame->bufsz = 0; - if (ws->mode == NNI_EP_MODE_DIAL) { - ws_mask_frame(frame); - } else { + if (ws->server) { frame->masked = false; + } else { + ws_mask_frame(frame); } wm->aio = NULL; @@ -375,10 +375,10 @@ ws_msg_init_tx(ws_msg **wmp, nni_ws *ws, nni_msg *msg, nni_aio *aio) frame->hlen += 8; } - if (ws->mode == NNI_EP_MODE_DIAL) { - ws_mask_frame(frame); - } else { + if (ws->server) { frame->masked = false; + } else { + ws_mask_frame(frame); } } while (len); @@ -960,12 +960,12 @@ ws_read_cb(void *arg) // here, because we don't have data yet.) if (frame->masked) { memcpy(frame->mask, frame->head + frame->hlen - 4, 4); - if (ws->mode == NNI_EP_MODE_DIAL) { + if (!ws->server) { ws_close(ws, WS_CLOSE_PROTOCOL_ERR); nni_mtx_unlock(&ws->mtx); return; } - } else if (ws->mode == NNI_EP_MODE_LISTEN) { + } else if (ws->server) { ws_close(ws, WS_CLOSE_PROTOCOL_ERR); nni_mtx_unlock(&ws->mtx); return; @@ -1369,13 +1369,10 @@ ws_http_cb(void *arg) nni_ws * ws = arg; nni_aio *aio = ws->httpaio; - switch (ws->mode) { - case NNI_EP_MODE_LISTEN: + if (ws->server) { ws_http_cb_listener(ws, aio); - break; - case NNI_EP_MODE_DIAL: + } else { ws_http_cb_dialer(ws, aio); - break; } } @@ -1586,7 +1583,7 @@ ws_handler(nni_aio *aio) ws->http = conn; ws->req = req; ws->res = res; - ws->mode = NNI_EP_MODE_LISTEN; + ws->server = true; ws->maxframe = l->maxframe; // XXX: Inherit fragmentation? (Frag is limited for now). @@ -2071,7 +2068,7 @@ nni_ws_dialer_dial(nni_ws_dialer *d, nni_aio *aio) } ws->dialer = d; ws->useraio = aio; - ws->mode = NNI_EP_MODE_DIAL; + ws->server = false; ws->maxframe = d->maxframe; nni_list_append(&d->wspend, ws); nni_http_client_connect(d->client, ws->connaio); |
