From d4238b8f97b83963523cecf18cd5a031bf8f06d3 Mon Sep 17 00:00:00 2001 From: "Jack R. Dunaway" Date: Thu, 5 Nov 2015 10:58:01 -0600 Subject: [PATCH] fixes #505 hang in websocket test --- src/transports/ws/cws.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/transports/ws/cws.c b/src/transports/ws/cws.c index 7842b6fd9..08b32a9cf 100644 --- a/src/transports/ws/cws.c +++ b/src/transports/ws/cws.c @@ -86,6 +86,9 @@ struct nn_cws { /* Used to wait before retrying to connect. */ struct nn_backoff retry; + /* Defines message validation and framing. */ + uint8_t msg_type; + /* State machine that handles the active part of the connection lifetime. */ struct nn_sws sws; @@ -143,6 +146,7 @@ int nn_cws_create (void *hint, struct nn_epbase **epbase) struct nn_cws *self; int reconnect_ivl; int reconnect_ivl_max; + int msg_type; size_t sz; /* Allocate the new endpoint object. */ @@ -235,6 +239,12 @@ int nn_cws_create (void *hint, struct nn_epbase **epbase) nn_epbase_getctx (&self->epbase)); self->state = NN_CWS_STATE_IDLE; nn_usock_init (&self->usock, NN_CWS_SRC_USOCK, &self->fsm); + + sz = sizeof (msg_type); + nn_epbase_getopt (&self->epbase, NN_WS, NN_WS_MSG_TYPE, + &msg_type, &sz); + nn_assert (sz == sizeof (msg_type)); + self->msg_type = (uint8_t) msg_type; sz = sizeof (reconnect_ivl); nn_epbase_getopt (&self->epbase, NN_SOL_SOCKET, NN_RECONNECT_IVL, @@ -330,8 +340,6 @@ static void nn_cws_handler (struct nn_fsm *self, int src, int type, NN_UNUSED void *srcptr) { struct nn_cws *cws; - int msg_type; - size_t sz; cws = nn_cont (self, struct nn_cws, fsm); @@ -414,13 +422,9 @@ static void nn_cws_handler (struct nn_fsm *self, int src, int type, case NN_CWS_SRC_USOCK: switch (type) { case NN_USOCK_CONNECTED: - sz = sizeof (msg_type); - nn_epbase_getopt (&cws->epbase, NN_WS, NN_WS_MSG_TYPE, - &msg_type, &sz); - nn_assert(sz == sizeof (msg_type)); nn_sws_start (&cws->sws, &cws->usock, NN_WS_CLIENT, nn_chunkref_data (&cws->resource), - nn_chunkref_data (&cws->remote_host), (uint8_t)msg_type); + nn_chunkref_data (&cws->remote_host), cws->msg_type); cws->state = NN_CWS_STATE_ACTIVE; cws->peer_gone = 0; nn_epbase_stat_increment (&cws->epbase,