Skip to content

Commit 54de177

Browse files
maciejbaczmanskijukkar
authored andcommitted
net: openthread: Remove dependency on CONFIG_POSIX_API
For CoAP utils, `CONFIG_POSIX_API` is required only for wrapping socket calls not to require `zsock` prefix. POSIX_API brings more features than needed, is still experimental in Zephyr and causes warnings on building. This commit changes net socket calls to use `zsock_` prefix and disables `CONFIG_POSIX_API` for OpenThread. Signed-off-by: Maciej Baczmanski <[email protected]>
1 parent 35f75b2 commit 54de177

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

samples/openthread/coap_client/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x8000
2828

2929
# Network sockets
3030
CONFIG_NET_SOCKETS=y
31-
CONFIG_POSIX_API=y
3231
CONFIG_NET_SOCKETS_POLL_MAX=4
3332

3433
# Same network Master Key for client and server

samples/openthread/coap_client/src/coap_client_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static int on_provisioning_reply(const struct coap_packet *response,
125125

126126
memcpy(&unique_local_addr.sin6_addr, payload, payload_size);
127127

128-
if (!inet_ntop(AF_INET6, payload, unique_local_addr_str,
128+
if (!zsock_inet_ntop(AF_INET6, payload, unique_local_addr_str,
129129
INET6_ADDRSTRLEN)) {
130130
LOG_ERR("Received data is not IPv6 address: %d", errno);
131131
ret = -errno;

samples/openthread/coap_server/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x8000
2121

2222
# Network sockets
2323
CONFIG_NET_SOCKETS=y
24-
CONFIG_POSIX_API=y
2524
CONFIG_NET_SOCKETS_POLL_MAX=4
2625

2726
# Same network Master Key for client and server

subsys/net/lib/coap_utils/coap_utils.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ LOG_MODULE_REGISTER(coap_utils, CONFIG_COAP_UTILS_LOG_LEVEL);
2424
#endif
2525

2626
const static int nfds = 1;
27-
static struct pollfd fds;
27+
static struct zsock_pollfd fds;
2828
static struct coap_reply replies[COAP_MAX_REPLIES];
2929
static int proto_family;
3030
static 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

5858
static void coap_close_socket(int socket)
5959
{
60-
(void)close(socket);
60+
(void)zsock_close(socket);
6161
}
6262

6363
static 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,
184184
static 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

Comments
 (0)