summaryrefslogtreecommitdiffstats
path: root/src/afb-websock.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-04-06 15:26:04 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-04-06 15:26:04 +0200
commitb75bbfd9bd96ad8bb7174a768ae70cf3e8c5af7a (patch)
tree0372d90b0db892cbf46caa80e18a12403cf6edc9 /src/afb-websock.c
parent46fa94d4edd7fa874e334ab51df34f7daca007ce (diff)
websocket first version works
Change-Id: I4db7d432ea5921636bb5033b8d31e91475cecc52 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-websock.c')
-rw-r--r--src/afb-websock.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/afb-websock.c b/src/afb-websock.c
index dab4aa09..797724ce 100644
--- a/src/afb-websock.c
+++ b/src/afb-websock.c
@@ -220,15 +220,21 @@ static const struct afb_req_itf wsreq_itf = {
struct afb_websock *afb_websock_create(struct afb_hreq *hreq)
{
+ int fd;
struct afb_websock *result;
+ fd = MHD_get_connection_info(hreq->connection,
+ MHD_CONNECTION_INFO_CONNECTION_FD)->connect_fd;
+ fd = dup(fd);
+ if (fd < 0)
+ return NULL;
+
result = malloc(sizeof * result);
if (result == NULL)
goto error;
result->connection = hreq->connection;
- result->fd = MHD_get_connection_info(hreq->connection,
- MHD_CONNECTION_INFO_CONNECTION_FD)->connect_fd;
+ result->fd = fd;
result->context = ctxClientGet(afb_hreq_context(hreq));
if (result->context == NULL)
goto error2;
@@ -255,6 +261,7 @@ error3:
error2:
free(result);
error:
+ close(fd);
return NULL;
}
@@ -346,7 +353,7 @@ static int aws_handle_json(struct afb_websock *aws, struct json_object *obj)
goto error;
verb = &api[lenapi+1];
for (lenverb = 0 ; verb[lenverb] && verb[lenverb] != '/' ; lenverb++);
- if (!lenverb || !verb[lenverb])
+ if (!lenverb || verb[lenverb])
goto error;
/* allocates the request data */