From f0731397ed8113766789bb212e72f8c067fef0c8 Mon Sep 17 00:00:00 2001 From: Frédéric Desbiens Date: Mon, 21 Jul 2025 12:27:42 -0400 Subject: Added error handling to the HTTPS sample. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Frédéric Desbiens --- samples/demo_netxduo_https.c | 47 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'samples/demo_netxduo_https.c') diff --git a/samples/demo_netxduo_https.c b/samples/demo_netxduo_https.c index c4553a67..258ceacf 100644 --- a/samples/demo_netxduo_https.c +++ b/samples/demo_netxduo_https.c @@ -1,3 +1,14 @@ +/*************************************************************************** + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2025 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + /* This is a small demo of the NetX Web HTTP Client/Server API running on a high-performance NetX TCP/IP stack. */ /* This demo works for IPv4 only */ @@ -358,6 +369,8 @@ extern const NX_SECURE_TLS_CRYPTO nx_crypto_tls_ciphers; #endif /*NX_WEB_HTTPS_ENABLE */ /* Define the RAM disk memory for FileX demo. */ +#define TOTAL_SECTORS 256 +#define SECTOR_SIZE 512 static UCHAR media_memory[4096]; static CHAR ram_disk_memory[4096]; static FX_MEDIA ram_disk; @@ -712,12 +725,15 @@ void https_server_thread_entry(ULONG thread_input) UINT status; UINT server_port; - - NX_PARAMETER_NOT_USED(thread_input); - - fx_media_format(&ram_disk, + /* Format the RAM disk - the memory for the RAM disk was setup in + tx_application_define above. + + Important Note: The user must ensure there is enough RAM for the format + specified. Otherwise, memory corruption can occur. + */ + status = fx_media_format(&ram_disk, _fx_ram_driver, // Driver entry ram_disk_memory, // RAM disk memory pointer media_memory, // Media buffer pointer @@ -726,14 +742,31 @@ UINT server_port; 1, // Number of FATs 32, // Directory Entries 0, // Hidden sectors - 256, // Total sectors - 512, // Sector size + TOTAL_SECTORS, // Total sectors + SECTOR_SIZE, // Sector size 8, // Sectors per cluster 1, // Heads 1); // Sectors per track + /* Determine if the RAM disk format was successful. */ + if (status != FX_SUCCESS) + { + /* Error formatting the RAM disk. */ + printf("HTTPS RAM disk format failed, error: %x\n", status); + return; + } + /* Open the RAM disk. */ - fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, media_memory, sizeof(media_memory)) ; + status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, + ram_disk_memory, media_memory, sizeof(media_memory)); + + /* Determine if the RAM disk open was successful. */ + if (status != FX_SUCCESS) + { + /* Error formatting the RAM disk. */ + printf("HTTPS RAM disk open failed, error: %x\n", status); + return; + } fx_file_create(&ram_disk, "TEST.TXT"); -- cgit v1.3.1 From e164cd8ddec052b536a458e39025fbe222084d15 Mon Sep 17 00:00:00 2001 From: Frédéric Desbiens Date: Mon, 28 Jul 2025 13:50:13 -0400 Subject: Ensure proper RAM Disk sizing in the HTTPS demo. --- samples/demo_netxduo_https.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'samples/demo_netxduo_https.c') diff --git a/samples/demo_netxduo_https.c b/samples/demo_netxduo_https.c index 258ceacf..27ad9784 100644 --- a/samples/demo_netxduo_https.c +++ b/samples/demo_netxduo_https.c @@ -372,7 +372,7 @@ extern const NX_SECURE_TLS_CRYPTO nx_crypto_tls_ciphers; #define TOTAL_SECTORS 256 #define SECTOR_SIZE 512 static UCHAR media_memory[4096]; -static CHAR ram_disk_memory[4096]; +static CHAR ram_disk_memory[TOTAL_SECTORS*SECTOR_SIZE]; static FX_MEDIA ram_disk; /* HTTP server stack area. */ -- cgit v1.3.1