@@ -33,6 +33,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
33
33
#include <zephyr/sys/printk.h>
34
34
#include <zephyr/types.h>
35
35
#include <zephyr/posix/fcntl.h>
36
+ #include <zephyr/zvfs/eventfd.h>
36
37
37
38
#if defined(CONFIG_LWM2M_DTLS_SUPPORT )
38
39
#include <zephyr/net/tls_credentials.h>
@@ -105,7 +106,6 @@ static struct zsock_pollfd sock_fds[MAX_POLL_FD];
105
106
106
107
static struct lwm2m_ctx * sock_ctx [MAX_POLL_FD ];
107
108
static int sock_nfds ;
108
- static int control_sock ;
109
109
110
110
/* Resource wrappers */
111
111
#if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER )
@@ -128,7 +128,7 @@ static int lwm2m_socket_update(struct lwm2m_ctx *ctx);
128
128
void lwm2m_engine_wake_up (void )
129
129
{
130
130
if (IS_ENABLED (CONFIG_LWM2M_TICKLESS )) {
131
- zsock_send ( control_sock , & ( char ){ 0 }, 1 , 0 );
131
+ zvfs_eventfd_write ( sock_fds [ MAX_POLL_FD - 1 ]. fd , 1 );
132
132
}
133
133
}
134
134
@@ -870,12 +870,12 @@ static void socket_loop(void *p1, void *p2, void *p3)
870
870
for (i = 0 ; i < MAX_POLL_FD ; i ++ ) {
871
871
short revents = sock_fds [i ].revents ;
872
872
873
- if (( revents & ZSOCK_POLLIN ) && sock_fds [ i ]. fd != -1 &&
874
- sock_ctx [ i ] == NULL ) {
873
+ if (IS_ENABLED ( CONFIG_LWM2M_TICKLESS ) && ( revents & ZSOCK_POLLIN ) &&
874
+ i == ( MAX_POLL_FD - 1 ) ) {
875
875
/* This is the control socket, just read and ignore the data */
876
- char tmp ;
876
+ zvfs_eventfd_t tmp ;
877
877
878
- zsock_recv (sock_fds [i ].fd , & tmp , 1 , 0 );
878
+ zvfs_eventfd_read (sock_fds [i ].fd , & tmp );
879
879
continue ;
880
880
}
881
881
if (sock_ctx [i ] != NULL && sock_ctx [i ]-> sock_fd < 0 ) {
@@ -1348,31 +1348,17 @@ static int lwm2m_engine_init(void)
1348
1348
}
1349
1349
1350
1350
if (IS_ENABLED (CONFIG_LWM2M_TICKLESS )) {
1351
- /* Create socketpair that is used to wake zsock_poll() in the main loop */
1352
- int s [2 ];
1353
- int ret = zsock_socketpair (AF_UNIX , SOCK_STREAM , 0 , s );
1351
+ /* Create eventfd that is used to wake zsock_poll() in the main loop */
1352
+ int efd = zvfs_eventfd (0 , ZVFS_EFD_NONBLOCK );
1354
1353
1355
- if (ret ) {
1356
- LOG_ERR ("Error; socketpair() returned %d" , ret );
1357
- return ret ;
1358
- }
1359
- /* Last poll-handle is reserved for control socket */
1360
- sock_fds [MAX_POLL_FD - 1 ].fd = s [0 ];
1361
- control_sock = s [1 ];
1362
- ret = zsock_fcntl (s [0 ], F_SETFL , O_NONBLOCK );
1363
- if (ret ) {
1364
- LOG_ERR ("zsock_fcntl() %d" , ret );
1365
- zsock_close (s [0 ]);
1366
- zsock_close (s [1 ]);
1367
- return ret ;
1368
- }
1369
- ret = zsock_fcntl (s [1 ], F_SETFL , O_NONBLOCK );
1370
- if (ret ) {
1371
- LOG_ERR ("zsock_fcntl() %d" , ret );
1372
- zsock_close (s [0 ]);
1373
- zsock_close (s [1 ]);
1374
- return ret ;
1354
+ if (efd == -1 ) {
1355
+ int err = errno ;
1356
+
1357
+ LOG_ERR ("Error; eventfd() returned %d" , err );
1358
+ return - err ;
1375
1359
}
1360
+ /* Last poll-handle is reserved for control eventfd */
1361
+ sock_fds [MAX_POLL_FD - 1 ].fd = efd ;
1376
1362
}
1377
1363
1378
1364
lwm2m_clear_block_contexts ();
0 commit comments