X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/ad9d01050b7b6d592a83ce14eeef7068bd981028..4c72c6901e007414aebb4cb6534c1a49d63558b0:/src/matrix_http_mongoose.c diff --git a/src/matrix_http_mongoose.c b/src/matrix_http_mongoose.c index 020b4c8..a514f72 100644 --- a/src/matrix_http_mongoose.c +++ b/src/matrix_http_mongoose.c @@ -36,7 +36,7 @@ MatrixHttpCallback( // If s_url is https://, tell client connection to use TLS if (mg_url_is_ssl(client->server)) { - struct mg_tls_opts opts; + static struct mg_tls_opts opts; opts.srvname = host; mg_tls_init(c, &opts); } @@ -56,7 +56,12 @@ MatrixHttpCallback( conn->dataLen = hm->body.len; conn->dataReceived = true; - printf("received[%d]:\n%.*s\n", conn->dataLen, conn->dataLen, conn->data); + //printf("received[%d]:\n%.*s\n", conn->dataLen, conn->dataLen, conn->data); + } + if (ev == MG_EV_CLOSE) + { + conn->connection = NULL; + conn->connected = false; } } @@ -71,7 +76,18 @@ MatrixHttpInit( mg_mgr_init(&conn->mgr); - mg_http_connect(&conn->mgr, client->server, MatrixHttpCallback, client); + 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); while (! conn->connected) mg_mgr_poll(&conn->mgr, 1000); @@ -100,6 +116,8 @@ MatrixHttpGet( bool authenticated) { MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData; + if (! conn->connected) + MatrixHttpConnect(client); conn->dataReceived = false; @@ -141,6 +159,8 @@ MatrixHttpPost( bool authenticated) { MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData; + if (! conn->connected) + MatrixHttpConnect(client); conn->dataReceived = false; @@ -186,6 +206,8 @@ MatrixHttpPut( bool authenticated) { MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData; + if (! conn->connected) + MatrixHttpConnect(client); conn->dataReceived = false;