summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Brooks <dave@bcs.co.nz>2012-04-20 12:16:52 +0800
committerAndy Green <andy.green@linaro.org>2012-04-20 12:27:24 +0800
commit993343b5e426000ef8e0a196730c3fd3ae4bbe89 (patch)
treef689ba0bd4a355c5b77a0512c1eabf0ffc23dda3
parent6c6a3d3caf37c78d0900e44543208606fa2db8a5 (diff)
set connection callback before connection completed to allow early messages
Signed-off-by: David Brooks <dave@bcs.co.nz> Signed-off-by: Andy Green <andy@warmcat.com> -- lib/client-handshake.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)
-rw-r--r--lib/client-handshake.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/client-handshake.c b/lib/client-handshake.c
index 76c297d..84b744f 100644
--- a/lib/client-handshake.c
+++ b/lib/client-handshake.c
@@ -241,14 +241,33 @@ libwebsocket_client_connect(struct libwebsocket_context *context,
} else
wsi->c_origin = NULL;
+ wsi->c_callback = NULL;
if (protocol) {
+ const char *pc;
+ struct libwebsocket_protocols *pp;
+
wsi->c_protocol = malloc(strlen(protocol) + 1);
if (wsi->c_protocol == NULL)
goto oom3;
+
strcpy(wsi->c_protocol, protocol);
+
+ pc = protocol;
+ while (*pc && *pc != ',')
+ pc++;
+ n = pc - protocol;
+ pp = context->protocols;
+ while (pp->name && !wsi->c_callback) {
+ if (!strncmp(protocol, pp->name, n))
+ wsi->c_callback = pp->callback;
+ pp++;
+ }
} else
wsi->c_protocol = NULL;
+ if (!wsi->c_callback)
+ wsi->c_callback = context->protocols[0].callback;
+
/* set up appropriate masking */
wsi->xor_mask = xor_no_mask;