X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-websock.c;h=cff995f28b7f7bfe493456eacfbf324025e275be;hb=8d21ca2e3daf37d8afe7b678edb0aa2e47a468ef;hp=dab4aa094407b78f446e8ff16b04111693a112ee;hpb=87d2ff17b84459e785c7820563bb0172849810c4;p=src%2Fapp-framework-binder.git diff --git a/src/afb-websock.c b/src/afb-websock.c index dab4aa09..cff995f2 100644 --- a/src/afb-websock.c +++ b/src/afb-websock.c @@ -27,10 +27,6 @@ #include #include -/* -#include -#include -*/ #include "websock.h" @@ -220,15 +216,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 +257,7 @@ error3: error2: free(result); error: + close(fd); return NULL; } @@ -346,7 +349,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 */ @@ -502,6 +505,7 @@ static void wsreq_reply(struct afb_wsreq *wsreq, int retcode, const char *status /* emits the reply */ message = json_object_to_json_string(reply); websock_text(wsreq->aws->ws, message, strlen(message)); + json_object_put(reply); /* TODO eliminates the wsreq */ }