Skip to content

Commit 3573810

Browse files
committed
app: Use NRF_MODEM_MAX_SOCKET_COUNT
File descriptor counting has been refactored in Zephyr. CONFIG_POSIX_OPEN_MAX should not be used anymore. SM should enable 8 sockets allowed by the modem and NRF_MODEM_MAX_SOCKET_COUNT is for this purpose. This was brought into NCS by the 2026.01.12 upmerge: nrfconnect/sdk-nrf#26468 Signed-off-by: Tommi Rantanen <tommi.rantanen@nordicsemi.no>
1 parent 6ac2239 commit 3573810

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

app/prj.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ CONFIG_NET_IPV6=y
3939
# Modem library
4040
CONFIG_NRF_MODEM_LIB=y
4141
CONFIG_AT_CMD_CUSTOM=y
42-
# Align the max FD entry to NRF_MODEM_MAX_SOCKET_COUNT(8)
43-
CONFIG_ZVFS_OPEN_MAX=8
4442

4543
# Handle modem fault
4644
CONFIG_NRF_MODEM_LIB_ON_FAULT_APPLICATION_SPECIFIC=y

app/src/sm_at_socket.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020

2121
LOG_MODULE_REGISTER(sm_sock, CONFIG_SM_LOG_LEVEL);
2222

23-
#define SM_FDS_COUNT CONFIG_POSIX_OPEN_MAX
24-
#define SM_MAX_SOCKET_COUNT (SM_FDS_COUNT - 1)
23+
/* Ensure the socket count so we do a change consciously when it is changed. */
24+
BUILD_ASSERT(NRF_MODEM_MAX_SOCKET_COUNT == 8, "NRF_MODEM_MAX_SOCKET_COUNT must be 8");
25+
26+
#define SM_MAX_SOCKET_COUNT NRF_MODEM_MAX_SOCKET_COUNT
2527

2628
/**@brief Socketopt operations. */
2729
enum sm_socketopt_operation {

app/tests/at_socket/src/test_at_socket.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,15 @@ void test_xsocket_invalid_type(void)
392392

393393
/*
394394
* Test: Create maximum number of sockets
395-
* - Tests that the application can create up to CONFIG_POSIX_OPEN_MAX-1 sockets
395+
* - Tests that the application can create up to NRF_MODEM_MAX_SOCKET_COUNT sockets
396396
* - Verifies that attempting to create one more socket fails
397397
*/
398398
void test_xsocket_max_sockets(void)
399399
{
400400
const char *response;
401-
int max_sockets = CONFIG_POSIX_OPEN_MAX - 1;
401+
int max_sockets = NRF_MODEM_MAX_SOCKET_COUNT;
402402

403-
/* Create 3 sockets (determined by CONFIG_POSIX_OPEN_MAX - 1) */
403+
/* Create 3 sockets (determined by NRF_MODEM_MAX_SOCKET_COUNT) */
404404
for (int i = 0; i < max_sockets; i++) {
405405

406406
/* Mock nrf_socket to return fd */
@@ -432,11 +432,11 @@ void test_xsocket_max_sockets(void)
432432

433433
/* Clean up: close all 3 sockets */
434434
for (int i = 0; i < max_sockets; i++) {
435+
char send_buf[20];
435436
__cmock_nrf_close_ExpectAndReturn(i, 0);
437+
sprintf(send_buf, "AT#XCLOSE=%d\r\n", i);
438+
send_at_command(send_buf);
436439
}
437-
send_at_command("AT#XCLOSE=0\r\n");
438-
send_at_command("AT#XCLOSE=1\r\n");
439-
send_at_command("AT#XCLOSE=2\r\n");
440440
}
441441

442442
/*
@@ -2051,7 +2051,7 @@ void test_xapoll_stop_socket(void)
20512051
void test_xapoll_start_all_sockets(void)
20522052
{
20532053
const char *response;
2054-
int max_sockets = CONFIG_POSIX_OPEN_MAX - 1;
2054+
int max_sockets = NRF_MODEM_MAX_SOCKET_COUNT;
20552055

20562056
/* Create multiple sockets */
20572057
for (int i = 0; i < max_sockets; i++) {
@@ -2075,11 +2075,11 @@ void test_xapoll_start_all_sockets(void)
20752075

20762076
/* Close all sockets */
20772077
for (int i = 0; i < max_sockets; i++) {
2078+
char send_buf[20];
20782079
__cmock_nrf_close_ExpectAndReturn(i, 0);
2080+
sprintf(send_buf, "AT#XCLOSE=%d\r\n", i);
2081+
send_at_command(send_buf);
20792082
}
2080-
send_at_command("AT#XCLOSE=0\r\n");
2081-
send_at_command("AT#XCLOSE=1\r\n");
2082-
send_at_command("AT#XCLOSE=2\r\n");
20832083
}
20842084

20852085
/*
@@ -2090,7 +2090,7 @@ void test_xapoll_start_all_sockets(void)
20902090
void test_xapoll_stop_all_sockets(void)
20912091
{
20922092
const char *response;
2093-
int max_sockets = CONFIG_POSIX_OPEN_MAX - 1;
2093+
int max_sockets = NRF_MODEM_MAX_SOCKET_COUNT;
20942094

20952095
/* Create multiple sockets */
20962096
for (int i = 0; i < max_sockets; i++) {
@@ -2118,11 +2118,11 @@ void test_xapoll_stop_all_sockets(void)
21182118

21192119
/* Close all sockets */
21202120
for (int i = 0; i < max_sockets; i++) {
2121+
char send_buf[20];
21212122
__cmock_nrf_close_ExpectAndReturn(i, 0);
2123+
sprintf(send_buf, "AT#XCLOSE=%d\r\n", i);
2124+
send_at_command(send_buf);
21222125
}
2123-
send_at_command("AT#XCLOSE=0\r\n");
2124-
send_at_command("AT#XCLOSE=1\r\n");
2125-
send_at_command("AT#XCLOSE=2\r\n");
21262126
}
21272127

21282128
/*
@@ -2234,7 +2234,7 @@ void test_xapoll_invalid_socket(void)
22342234
void test_xclose_operation(void)
22352235
{
22362236
const char *response;
2237-
int max_sockets = CONFIG_POSIX_OPEN_MAX - 1;
2237+
int max_sockets = NRF_MODEM_MAX_SOCKET_COUNT;
22382238

22392239
/* Test 1: Close single socket using handle */
22402240
/* Create one socket */

0 commit comments

Comments
 (0)