]> gitweb.ps.run Git - matrix_esp_thesis/blobdiff - src/matrix_http_mongoose.c
esp32 build, cli
[matrix_esp_thesis] / src / matrix_http_mongoose.c
index 020b4c8cf638256edc9db6a521b454f7c71c4f98..a514f72b301eccef9009d466fee310228d82d024 100644 (file)
@@ -36,7 +36,7 @@ MatrixHttpCallback(
         // If s_url is https://, tell client connection to use TLS\r
         if (mg_url_is_ssl(client->server))\r
         {\r
-            struct mg_tls_opts opts;\r
+            static struct mg_tls_opts opts;\r
             opts.srvname = host;\r
             mg_tls_init(c, &opts);\r
         }\r
@@ -56,7 +56,12 @@ MatrixHttpCallback(
         conn->dataLen = hm->body.len;\r
         conn->dataReceived = true;\r
 \r
-        printf("received[%d]:\n%.*s\n", conn->dataLen, conn->dataLen, conn->data);\r
+        //printf("received[%d]:\n%.*s\n", conn->dataLen, conn->dataLen, conn->data);\r
+    }\r
+    if (ev == MG_EV_CLOSE)\r
+    {\r
+        conn->connection = NULL;\r
+        conn->connected = false;\r
     }\r
 }\r
 \r
@@ -71,7 +76,18 @@ MatrixHttpInit(
     \r
     mg_mgr_init(&conn->mgr);\r
 \r
-    mg_http_connect(&conn->mgr, client->server, MatrixHttpCallback, client);\r
+    return MatrixHttpConnect(client);\r
+}\r
+\r
+bool\r
+MatrixHttpConnect(\r
+    MatrixClient * client)\r
+{\r
+    MatrixHttpConnection * conn =\r
+        (MatrixHttpConnection *)client->httpUserData;\r
+    \r
+    //struct mg_connection * c =\r
+        mg_http_connect(&conn->mgr, client->server, MatrixHttpCallback, client);\r
 \r
     while (! conn->connected)\r
         mg_mgr_poll(&conn->mgr, 1000);\r
@@ -100,6 +116,8 @@ MatrixHttpGet(
     bool authenticated)\r
 {\r
     MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData;\r
+    if (! conn->connected)\r
+        MatrixHttpConnect(client);\r
 \r
     conn->dataReceived = false;\r
 \r
@@ -141,6 +159,8 @@ MatrixHttpPost(
     bool authenticated)\r
 {\r
     MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData;\r
+    if (! conn->connected)\r
+        MatrixHttpConnect(client);\r
 \r
     conn->dataReceived = false;\r
 \r
@@ -186,6 +206,8 @@ MatrixHttpPut(
     bool authenticated)\r
 {\r
     MatrixHttpConnection * conn = (MatrixHttpConnection *)client->httpUserData;\r
+    if (! conn->connected)\r
+        MatrixHttpConnect(client);\r
 \r
     conn->dataReceived = false;\r
 \r