Skip to content

Commit f073139

Browse files
committed
Added error handling to the HTTPS sample.
Signed-off-by: Frédéric Desbiens <frederic.desbiens@eclipse-foundation.org>
1 parent 5af33d7 commit f073139

1 file changed

Lines changed: 40 additions & 7 deletions

File tree

samples/demo_netxduo_https.c

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/***************************************************************************
2+
* Copyright (c) 2024 Microsoft Corporation
3+
* Copyright (c) 2025 Eclipse ThreadX contributors
4+
*
5+
* This program and the accompanying materials are made available under the
6+
* terms of the MIT License which is available at
7+
* https://opensource.org/licenses/MIT.
8+
*
9+
* SPDX-License-Identifier: MIT
10+
**************************************************************************/
11+
112
/* This is a small demo of the NetX Web HTTP Client/Server API running on a
213
high-performance NetX TCP/IP stack. */
314
/* This demo works for IPv4 only */
@@ -358,6 +369,8 @@ extern const NX_SECURE_TLS_CRYPTO nx_crypto_tls_ciphers;
358369
#endif /*NX_WEB_HTTPS_ENABLE */
359370

360371
/* Define the RAM disk memory for FileX demo. */
372+
#define TOTAL_SECTORS 256
373+
#define SECTOR_SIZE 512
361374
static UCHAR media_memory[4096];
362375
static CHAR ram_disk_memory[4096];
363376
static FX_MEDIA ram_disk;
@@ -712,12 +725,15 @@ void https_server_thread_entry(ULONG thread_input)
712725
UINT status;
713726
UINT server_port;
714727

715-
716-
717728
NX_PARAMETER_NOT_USED(thread_input);
718729

719-
720-
fx_media_format(&ram_disk,
730+
/* Format the RAM disk - the memory for the RAM disk was setup in
731+
tx_application_define above.
732+
733+
Important Note: The user must ensure there is enough RAM for the format
734+
specified. Otherwise, memory corruption can occur.
735+
*/
736+
status = fx_media_format(&ram_disk,
721737
_fx_ram_driver, // Driver entry
722738
ram_disk_memory, // RAM disk memory pointer
723739
media_memory, // Media buffer pointer
@@ -726,14 +742,31 @@ UINT server_port;
726742
1, // Number of FATs
727743
32, // Directory Entries
728744
0, // Hidden sectors
729-
256, // Total sectors
730-
512, // Sector size
745+
TOTAL_SECTORS, // Total sectors
746+
SECTOR_SIZE, // Sector size
731747
8, // Sectors per cluster
732748
1, // Heads
733749
1); // Sectors per track
734750

751+
/* Determine if the RAM disk format was successful. */
752+
if (status != FX_SUCCESS)
753+
{
754+
/* Error formatting the RAM disk. */
755+
printf("HTTPS RAM disk format failed, error: %x\n", status);
756+
return;
757+
}
758+
735759
/* Open the RAM disk. */
736-
fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, media_memory, sizeof(media_memory)) ;
760+
status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver,
761+
ram_disk_memory, media_memory, sizeof(media_memory));
762+
763+
/* Determine if the RAM disk open was successful. */
764+
if (status != FX_SUCCESS)
765+
{
766+
/* Error formatting the RAM disk. */
767+
printf("HTTPS RAM disk open failed, error: %x\n", status);
768+
return;
769+
}
737770

738771
fx_file_create(&ram_disk, "TEST.TXT");
739772

0 commit comments

Comments
 (0)