Proyecto integrador para asignatura de Especialización
Revision 16:1374b4c35897, committed 2017-09-04
- Comitter:
- Jan Jongboom
- Date:
- Mon Sep 04 16:32:38 2017 +0100
- Parent:
- 15:65a49b573ba5
- Child:
- 17:97b1dd566b07
- Commit message:
- Update mbed-http, was leaking 1024 bytes of memory in tls_socket
Changed in this revision
--- a/mbed-http.lib Thu Jul 27 15:08:59 2017 +0200 +++ b/mbed-http.lib Mon Sep 04 16:32:38 2017 +0100 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/sandbox/code/mbed-http/#3004056e4661 +https://developer.mbed.org/teams/sandbox/code/mbed-http/#f7a85895a941
--- a/mbed_app.json Thu Jul 27 15:08:59 2017 +0200
+++ b/mbed_app.json Mon Sep 04 16:32:38 2017 +0100
@@ -18,7 +18,7 @@
},
"esp8266-debug": {
"value": false
- },
+ },
"wifi-ssid": {
"value": "\"SSID\""
},
@@ -26,8 +26,9 @@
"value": "\"Password\""
}
},
- "macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_entropy_config.h\"",
- "MBEDTLS_TEST_NULL_ENTROPY", "MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES" ],
+ "macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_entropy_config.h\"",
+ "MBEDTLS_TEST_NULL_ENTROPY", "MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES",
+ "MBED_HEAP_STATS_ENABLED=1" ],
"target_overrides": {
"*": {
"target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"],
--- a/source/main-https-socket-reuse.cpp Thu Jul 27 15:08:59 2017 +0200
+++ b/source/main-https-socket-reuse.cpp Mon Sep 04 16:32:38 2017 +0100
@@ -9,6 +9,7 @@
#include "mbed.h"
#include "easy-connect.h"
#include "https_request.h"
+#include "mbed_stats.h"
Serial pc(USBTX, USBRX);
@@ -55,14 +56,20 @@
mbedtls_printf("\nBody (%d bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
}
-int main() {
- pc.baud(115200);
+void run() {
+ mbed_stats_heap_t heap_stats;
+
+ mbed_stats_heap_get(&heap_stats);
+ printf("[1] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
NetworkInterface* network = easy_connect(true);
if (!network) {
- return 1;
+ return;
}
+ mbed_stats_heap_get(&heap_stats);
+ printf("[2] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
+
// Create a TLS socket (which holds a TCPSocket)
printf("\n----- Setting up TLS connection -----\n");
@@ -70,9 +77,12 @@
socket->set_debug(true);
if (socket->connect() != 0) {
printf("TLS Connect failed %d\n", socket->error());
- return 1;
+ return;
}
+ mbed_stats_heap_get(&heap_stats);
+ printf("[3] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
+
// GET request to httpbin.org
{
HttpsRequest* get_req = new HttpsRequest(socket, HTTP_GET, "https://httpbin.org/status/418");
@@ -81,14 +91,20 @@
HttpResponse* get_res = get_req->send();
if (!get_res) {
printf("HttpRequest failed (error code %d)\n", get_req->get_error());
- return 1;
+ return;
}
printf("\n----- HTTPS GET response -----\n");
dump_response(get_res);
+ mbed_stats_heap_get(&heap_stats);
+ printf("[4a] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
+
delete get_req;
}
+ mbed_stats_heap_get(&heap_stats);
+ printf("[4] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
+
// POST request to httpbin.org
{
HttpsRequest* post_req = new HttpsRequest(socket, HTTP_POST, "https://httpbin.org/post");
@@ -100,7 +116,7 @@
HttpResponse* post_res = post_req->send(body, strlen(body));
if (!post_res) {
printf("HttpRequest failed (error code %d)\n", post_req->get_error());
- return 1;
+ return;
}
printf("\n----- HTTPS POST response -----\n");
@@ -109,8 +125,23 @@
delete post_req;
}
+ mbed_stats_heap_get(&heap_stats);
+ printf("[5] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
+
delete socket;
+ mbed_stats_heap_get(&heap_stats);
+ printf("[6] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
+
+ Thread::wait(osWaitForever);
+}
+
+int main() {
+ pc.baud(115200);
+
+ Thread t(osPriorityNormal, 8 * 1024);
+ t.start(&run);
+
Thread::wait(osWaitForever);
}
--- a/source/select-demo.h Thu Jul 27 15:08:59 2017 +0200 +++ b/source/select-demo.h Mon Sep 04 16:32:38 2017 +0100 @@ -6,6 +6,6 @@ #define DEMO_HTTPS 3 #define DEMO_HTTPS_SOCKET_REUSE 4 -#define DEMO DEMO_HTTP +#define DEMO DEMO_HTTPS_SOCKET_REUSE #endif // _SELECT_METHOD_H_