Skip to content

Commit 71f85cc

Browse files
author
Daniel Campora
committed
cc3200: Close ftp and telnet server sockets if listening fails.
1 parent 53a8aeb commit 71f85cc

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

cc3200/ftp/ftp.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,19 +443,22 @@ static bool ftp_create_listening_socket (_i16 *sd, _u16 port, _u8 backlog) {
443443

444444
// Enable non-blocking mode
445445
nonBlockingOption.NonblockingEnabled = 1;
446-
ASSERT (sl_SetSockOpt(_sd, SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption)) == SL_SOC_OK);
446+
ASSERT ((result = sl_SetSockOpt(_sd, SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK);
447447

448448
// Bind the socket to a port number
449449
sServerAddress.sin_family = AF_INET;
450450
sServerAddress.sin_addr.s_addr = INADDR_ANY;
451451
sServerAddress.sin_port = htons(port);
452452

453-
ASSERT (sl_Bind(_sd, (const SlSockAddr_t *)&sServerAddress, sizeof(sServerAddress)) == SL_SOC_OK);
453+
ASSERT ((result |= sl_Bind(_sd, (const SlSockAddr_t *)&sServerAddress, sizeof(sServerAddress))) == SL_SOC_OK);
454454

455455
// Start listening
456-
ASSERT ((result = sl_Listen (_sd, backlog)) == SL_SOC_OK);
456+
ASSERT ((result |= sl_Listen (_sd, backlog)) == SL_SOC_OK);
457457

458-
return (result == SL_SOC_OK) ? true : false;
458+
if (result == SL_SOC_OK) {
459+
return true;
460+
}
461+
servers_close_socket(sd);
459462
}
460463
return false;
461464
}

cc3200/telnet/telnet.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,22 @@ static bool telnet_create_socket (void) {
334334

335335
// Enable non-blocking mode
336336
nonBlockingOption.NonblockingEnabled = 1;
337-
ASSERT (sl_SetSockOpt(telnet_data.sd, SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption)) == SL_SOC_OK);
337+
ASSERT ((result = sl_SetSockOpt(telnet_data.sd, SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingOption, sizeof(nonBlockingOption))) == SL_SOC_OK);
338338

339339
// Bind the socket to a port number
340340
sServerAddress.sin_family = AF_INET;
341341
sServerAddress.sin_addr.s_addr = INADDR_ANY;
342342
sServerAddress.sin_port = htons(TELNET_PORT);
343343

344-
ASSERT (sl_Bind(telnet_data.sd, (const SlSockAddr_t *)&sServerAddress, sizeof(sServerAddress)) == SL_SOC_OK);
344+
ASSERT ((result |= sl_Bind(telnet_data.sd, (const SlSockAddr_t *)&sServerAddress, sizeof(sServerAddress))) == SL_SOC_OK);
345345

346346
// Start listening
347-
ASSERT ((result = sl_Listen (telnet_data.sd, TELNET_MAX_CLIENTS)) == SL_SOC_OK);
347+
ASSERT ((result |= sl_Listen (telnet_data.sd, TELNET_MAX_CLIENTS)) == SL_SOC_OK);
348348

349-
return (result == SL_SOC_OK) ? true : false;
349+
if (result == SL_SOC_OK) {
350+
return true;
351+
}
352+
servers_close_socket(&telnet_data.sd);
350353
}
351354

352355
return false;

0 commit comments

Comments
 (0)