X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/1273c8ea309926e377cbd5cc6dab6740910aa6ff..6646bd126f9faf1e687b203512d29da243acaa90:/src/matrix_http_mongoose.c diff --git a/src/matrix_http_mongoose.c b/src/matrix_http_mongoose.c index 2e500d6..0b6c267 100644 --- a/src/matrix_http_mongoose.c +++ b/src/matrix_http_mongoose.c @@ -58,6 +58,11 @@ MatrixHttpCallback( printf("received[%d]:\n%.*s\n", conn->dataLen, conn->dataLen, conn->data); } + if (ev == MG_EV_CLOSE) + { + conn->connection = NULL; + conn->connected = false; + } } bool @@ -71,6 +76,16 @@ MatrixHttpInit( mg_mgr_init(&conn->mgr); + return MatrixHttpConnect(client); +} + +bool +MatrixHttpConnect( + MatrixClient * client) +{ + MatrixHttpConnection * conn = + (MatrixHttpConnection *)client->httpUserData; + struct mg_connection * c = mg_http_connect(&conn->mgr, client->server, MatrixHttpCallback, client); @@ -101,6 +116,8 @@ MatrixHttpGet( bool authenticated) { MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData; + if (! conn->connected) + MatrixHttpConnect(client); conn->dataReceived = false; @@ -142,6 +159,8 @@ MatrixHttpPost( bool authenticated) { MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData; + if (! conn->connected) + MatrixHttpConnect(client); conn->dataReceived = false; @@ -187,6 +206,8 @@ MatrixHttpPut( bool authenticated) { MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData; + if (! conn->connected) + MatrixHttpConnect(client); conn->dataReceived = false; @@ -199,20 +220,6 @@ MatrixHttpPut( else authorizationHeader[0] = '\0'; - printf("PUT %s HTTP/1.0\r\n" - "Host: %.*s\r\n" - "%s" - "Content-Type: application/json\r\n" - "Content-Length: %d\r\n" - "\r\n" - "%s" - "\r\n", - url, - host.len, host.ptr, - authorizationHeader, - strlen(requestBuffer), - requestBuffer); - mg_printf(conn->connection, "PUT %s HTTP/1.0\r\n" "Host: %.*s\r\n"