@@ -16,7 +16,8 @@ LOG_MODULE_DECLARE(net_coap, CONFIG_COAP_LOG_LEVEL);
16
16
#include <zephyr/net/coap_link_format.h>
17
17
#include <zephyr/net/coap_mgmt.h>
18
18
#include <zephyr/net/coap_service.h>
19
- #include <zephyr/posix/fcntl.h>
19
+ #include <zephyr/sys/fdtable.h>
20
+ #include <zephyr/zvfs/eventfd.h>
20
21
21
22
#if defined(CONFIG_NET_TC_THREAD_COOPERATIVE )
22
23
/* Lowest priority cooperative thread */
@@ -38,7 +39,7 @@ LOG_MODULE_DECLARE(net_coap, CONFIG_COAP_LOG_LEVEL);
38
39
BUILD_ASSERT (CONFIG_ZVFS_POLL_MAX > 0 , "CONFIG_ZVFS_POLL_MAX can't be 0" );
39
40
40
41
static K_MUTEX_DEFINE (lock );
41
- static int control_socks [ 2 ] ;
42
+ static int control_sock ;
42
43
43
44
#if defined(CONFIG_COAP_SERVER_PENDING_ALLOCATOR_STATIC )
44
45
K_MEM_SLAB_DEFINE_STATIC (pending_data , CONFIG_COAP_SERVER_MESSAGE_SIZE ,
@@ -370,7 +371,7 @@ static int coap_server_poll_timeout(void)
370
371
371
372
static void coap_server_update_services (void )
372
373
{
373
- if (zsock_send ( control_socks [ 1 ], & ( char ){ 0 }, 1 , 0 ) < 0 ) {
374
+ if (zvfs_eventfd_write ( control_sock , 1 ) ) {
374
375
LOG_ERR ("Failed to notify server thread (%d)" , errno );
375
376
}
376
377
}
@@ -468,7 +469,7 @@ int coap_service_start(const struct coap_service *service)
468
469
goto end ;
469
470
}
470
471
471
- ret = zsock_fcntl (service -> data -> sock_fd , F_SETFL , O_NONBLOCK );
472
+ ret = zsock_fcntl (service -> data -> sock_fd , ZVFS_F_SETFL , ZVFS_O_NONBLOCK );
472
473
if (ret < 0 ) {
473
474
ret = - errno ;
474
475
goto close ;
@@ -763,25 +764,12 @@ static void coap_server_thread(void *p1, void *p2, void *p3)
763
764
ARG_UNUSED (p2 );
764
765
ARG_UNUSED (p3 );
765
766
766
- /* Create a socket pair to wake zsock_poll */
767
- ret = zsock_socketpair (AF_UNIX , SOCK_STREAM , 0 , control_socks );
768
- if (ret < 0 ) {
769
- LOG_ERR ("Failed to create socket pair (%d)" , ret );
767
+ control_sock = zvfs_eventfd (0 , ZVFS_EFD_NONBLOCK );
768
+ if (control_sock < 0 ) {
769
+ LOG_ERR ("Failed to create event fd (%d)" , - errno );
770
770
return ;
771
771
}
772
772
773
- for (int i = 0 ; i < 2 ; ++ i ) {
774
- ret = zsock_fcntl (control_socks [i ], F_SETFL , O_NONBLOCK );
775
-
776
- if (ret < 0 ) {
777
- zsock_close (control_socks [0 ]);
778
- zsock_close (control_socks [1 ]);
779
-
780
- LOG_ERR ("Failed to set socket pair [%d] non-blocking (%d)" , i , ret );
781
- return ;
782
- }
783
- }
784
-
785
773
COAP_SERVICE_FOREACH (svc ) {
786
774
if (svc -> flags & COAP_SERVICE_AUTOSTART ) {
787
775
ret = coap_service_start (svc );
@@ -810,9 +798,9 @@ static void coap_server_thread(void *p1, void *p2, void *p3)
810
798
sock_nfds ++ ;
811
799
}
812
800
813
- /* Add socket pair FD to allow wake up */
801
+ /* Add event FD to allow wake up */
814
802
if (sock_nfds < MAX_POLL_FD ) {
815
- sock_fds [sock_nfds ].fd = control_socks [ 0 ] ;
803
+ sock_fds [sock_nfds ].fd = control_sock ;
816
804
sock_fds [sock_nfds ].events = ZSOCK_POLLIN ;
817
805
sock_fds [sock_nfds ].revents = 0 ;
818
806
sock_nfds ++ ;
@@ -828,11 +816,11 @@ static void coap_server_thread(void *p1, void *p2, void *p3)
828
816
829
817
for (int i = 0 ; i < sock_nfds ; ++ i ) {
830
818
/* Check the wake up event */
831
- if (sock_fds [i ].fd == control_socks [ 0 ] &&
819
+ if (sock_fds [i ].fd == control_sock &&
832
820
sock_fds [i ].revents & ZSOCK_POLLIN ) {
833
- char tmp ;
821
+ zvfs_eventfd_t tmp ;
834
822
835
- zsock_recv (sock_fds [i ].fd , & tmp , 1 , 0 );
823
+ zvfs_eventfd_read (sock_fds [i ].fd , & tmp );
836
824
continue ;
837
825
}
838
826
0 commit comments