@@ -24,7 +24,7 @@ LOG_MODULE_REGISTER(coap_utils, CONFIG_COAP_UTILS_LOG_LEVEL);
2424#endif
2525
2626const static int nfds = 1 ;
27- static struct pollfd fds ;
27+ static struct zsock_pollfd fds ;
2828static struct coap_reply replies [COAP_MAX_REPLIES ];
2929static int proto_family ;
3030static struct sockaddr * bind_addr ;
@@ -37,7 +37,7 @@ static int coap_open_socket(void)
3737 int sock ;
3838
3939 while (1 ) {
40- sock = socket (proto_family , SOCK_DGRAM , IPPROTO_UDP );
40+ sock = zsock_socket (proto_family , SOCK_DGRAM , IPPROTO_UDP );
4141 if (sock < 0 ) {
4242 LOG_ERR ("Failed to create socket %d" , errno );
4343 k_sleep (K_MSEC (COAP_OPEN_SOCKET_SLEEP ));
@@ -47,7 +47,7 @@ static int coap_open_socket(void)
4747 }
4848
4949 if (bind_addr ) {
50- if (bind (sock , bind_addr , sizeof (* bind_addr ))) {
50+ if (zsock_bind (sock , bind_addr , sizeof (* bind_addr ))) {
5151 LOG_ERR ("Failed to bind socket, errno: %d" , errno );
5252 }
5353 }
@@ -57,7 +57,7 @@ static int coap_open_socket(void)
5757
5858static void coap_close_socket (int socket )
5959{
60- (void )close (socket );
60+ (void )zsock_close (socket );
6161}
6262
6363static void coap_receive (void )
@@ -73,25 +73,25 @@ static void coap_receive(void)
7373 while (1 ) {
7474 fds .revents = 0 ;
7575
76- if (poll (& fds , nfds , -1 ) < 0 ) {
76+ if (zsock_poll (& fds , nfds , -1 ) < 0 ) {
7777 LOG_ERR ("Error in poll:%d" , errno );
7878 errno = 0 ;
7979 k_sleep (K_MSEC (COAP_POOL_SLEEP ));
8080 continue ;
8181 }
8282
83- if (fds .revents & POLLERR ) {
83+ if (fds .revents & ZSOCK_POLLERR ) {
8484 LOG_ERR ("Error in poll.. waiting a moment." );
8585 k_sleep (K_MSEC (COAP_POOL_SLEEP ));
8686 continue ;
8787 }
8888
89- if (fds .revents & POLLHUP ) {
89+ if (fds .revents & ZSOCK_POLLHUP ) {
9090 LOG_ERR ("Error in poll: POLLHUP" );
9191 continue ;
9292 }
9393
94- if (fds .revents & POLLNVAL ) {
94+ if (fds .revents & ZSOCK_POLLNVAL ) {
9595 LOG_ERR ("Error in poll: POLLNVAL - fd not open" );
9696
9797 coap_close_socket (fds .fd );
@@ -102,13 +102,13 @@ static void coap_receive(void)
102102 continue ;
103103 }
104104
105- if (!(fds .revents & POLLIN )) {
105+ if (!(fds .revents & ZSOCK_POLLIN )) {
106106 LOG_ERR ("Unknown poll error" );
107107 continue ;
108108 }
109109
110110 from_addr_len = sizeof (from_addr );
111- len = recvfrom (fds .fd , buf , sizeof (buf ) - 1 , 0 , & from_addr ,
111+ len = zsock_recvfrom (fds .fd , buf , sizeof (buf ) - 1 , 0 , & from_addr ,
112112 & from_addr_len );
113113
114114 if (len < 0 ) {
@@ -184,7 +184,7 @@ static int coap_init_request(enum coap_method method,
184184static int coap_send_message (const struct sockaddr * addr ,
185185 struct coap_packet * request )
186186{
187- return sendto (fds .fd , request -> data , request -> offset , 0 , addr ,
187+ return zsock_sendto (fds .fd , request -> data , request -> offset , 0 , addr ,
188188 sizeof (* addr ));
189189}
190190
@@ -207,7 +207,7 @@ void coap_init(int ip_family, struct sockaddr *addr)
207207 bind_addr = addr ;
208208 }
209209
210- fds .events = POLLIN ;
210+ fds .events = ZSOCK_POLLIN ;
211211 fds .revents = 0 ;
212212 fds .fd = coap_open_socket ();
213213
0 commit comments