X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/ad9d01050b7b6d592a83ce14eeef7068bd981028..6646bd126f9faf1e687b203512d29da243acaa90:/src/matrix_http_mongoose.c diff --git a/src/matrix_http_mongoose.c b/src/matrix_http_mongoose.c index 020b4c8..0b6c267 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); } @@ -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,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;