summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-04-21 17:48:00 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-04-21 17:48:00 +0200
commit289017821655e0d9750eb7d5ae82c23790422a50 (patch)
treefbe38ec111cf829c8c8455cb494e7db1f00e694c
parent5eaa2c12a8b89f8a16f0759db88d65b56c82918c (diff)
websocket implementing cleanup
Change-Id: I85ee8eb60ef5d37ce1a82044ae317d2a17d3bec8 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-websock.c2
-rw-r--r--src/afb-ws-json.c28
2 files changed, 12 insertions, 18 deletions
diff --git a/src/afb-websock.c b/src/afb-websock.c
index 283a88bc..b4ad57a1 100644
--- a/src/afb-websock.c
+++ b/src/afb-websock.c
@@ -162,7 +162,7 @@ static int check_websocket_upgrade(struct MHD_Connection *con, const struct prot
}
/* create the web socket */
- ws = proto->create(dup(MHD_get_connection_info(con, MHD_CONNECTION_INFO_CONNECTION_FD)->connect_fd),
+ ws = proto->create(MHD_get_connection_info(con, MHD_CONNECTION_INFO_CONNECTION_FD)->connect_fd,
context,
(void*)MHD_resume_connection,
con);
diff --git a/src/afb-ws-json.c b/src/afb-ws-json.c
index 6fc6e3b3..9387f8d7 100644
--- a/src/afb-ws-json.c
+++ b/src/afb-ws-json.c
@@ -32,13 +32,12 @@
#include "afb-req-itf.h"
#include "afb-apis.h"
-static void aws_on_close(struct afb_ws_json *ws, uint16_t code, char *text, size_t size);
+static void aws_on_hangup(struct afb_ws_json *ws);
static void aws_on_text(struct afb_ws_json *ws, char *text, size_t size);
static struct afb_ws_itf aws_itf = {
- .on_close = (void*)aws_on_close,
- .on_text = (void*)aws_on_text,
- .on_binary = NULL,
+ .on_hangup = (void*)aws_on_hangup,
+ .on_text = (void*)aws_on_text
};
struct afb_wsreq;
@@ -53,7 +52,6 @@ struct afb_ws_json
struct afb_ws *ws;
};
-
static void aws_send_event(struct afb_ws_json *ws, const char *event, struct json_object *object);
static const struct afb_event_sender_itf event_sender_itf = {
@@ -104,10 +102,14 @@ error:
return NULL;
}
-static void aws_on_close(struct afb_ws_json *ws, uint16_t code, char *text, size_t size)
+static void aws_on_hangup(struct afb_ws_json *ws)
{
- /* do nothing but free the text */
- free(text);
+ ctxClientEventSenderRemove(ws->context, (struct afb_event_sender){ .itf = &event_sender_itf, .closure = ws });
+ afb_ws_destroy(ws->ws);
+ json_tokener_free(ws->tokener);
+ if (ws->cleanup != NULL)
+ ws->cleanup(ws->cleanup_closure);
+ free(ws);
}
#define CALL 2
@@ -281,14 +283,6 @@ static int aws_wsreq_parse(struct afb_wsreq *r, char *text, size_t size)
/* done */
r->text = text;
r->size = size;
-fprintf(stderr, "\n\nONTEXT([%d, %.*s, %.*s/%.*s, %.*s, %.*s])\n\n",
- r->code,
- (int)r->idlen, r->id,
- (int)r->apilen, r->api,
- (int)r->verblen, r->verb,
- (int)r->objlen, r->obj,
- (int)r->toklen, r->tok
-);
return 1;
bad_header:
@@ -323,7 +317,7 @@ bad_header:
free(wsreq);
alloc_error:
free(text);
- afb_ws_close(ws->ws, 1008);
+ afb_ws_close(ws->ws, 1008, NULL);
return;
}