Skip to content

Commit ca5ec1f

Browse files
committed
app: Move from nrf_ to zsock_ socket operations
Replace nrf_ socket operations with offloaded zsock_ socket operations. Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
1 parent 4dfd28e commit ca5ec1f

6 files changed

Lines changed: 229 additions & 228 deletions

File tree

app/src/sm_at_httpc.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <zephyr/sys/util.h>
1111
#include <zephyr/net/http/parser_url.h>
1212
#include <nrf_socket.h>
13+
#include <zephyr/net/socket.h>
1314
#include <modem/at_parser.h>
1415
#include <stdio.h>
1516
#include <string.h>
@@ -374,7 +375,7 @@ static int http_start_request(struct http_request *req)
374375
return -EINVAL;
375376
}
376377

377-
ret = set_xapoll_events(sock, NRF_POLLOUT | NRF_POLLIN);
378+
ret = set_xapoll_events(sock, ZSOCK_POLLOUT | ZSOCK_POLLIN);
378379
if (ret) {
379380
LOG_ERR("Failed to set XAPOLL events: %d", ret);
380381
return ret;
@@ -692,12 +693,12 @@ static int http_recv_read(struct http_request *req, struct sm_socket *sock)
692693
{
693694
int ret;
694695

695-
ret = nrf_recv(req->fd, req->recv_buf + req->recv_buf_len,
696-
HTTP_RECV_BUF_SIZE - req->recv_buf_len - 1, NRF_MSG_DONTWAIT);
696+
ret = zsock_recv(req->fd, req->recv_buf + req->recv_buf_len,
697+
HTTP_RECV_BUF_SIZE - req->recv_buf_len - 1, MSG_DONTWAIT);
697698

698699
if (ret < 0) {
699700
if (errno == EAGAIN || errno == EWOULDBLOCK) {
700-
set_xapoll_events(sock, NRF_POLLIN);
701+
set_xapoll_events(sock, ZSOCK_POLLIN);
701702
return -1;
702703
}
703704
if (errno == ETIMEDOUT) {
@@ -726,7 +727,7 @@ static void http_process_recv_headers(struct http_request *req, struct sm_socket
726727
char *header_end = strstr((char *)req->recv_buf, "\r\n\r\n");
727728

728729
if (header_end) {
729-
if (http_headers_complete(req, header_end, sock, events & NRF_POLLHUP)) {
730+
if (http_headers_complete(req, header_end, sock, events & ZSOCK_POLLHUP)) {
730731
return;
731732
}
732733
req->need_rearm_pollin = true;
@@ -750,7 +751,7 @@ static void http_process_recv_body(struct http_request *req, struct sm_socket *s
750751
if (req->manual_mode) {
751752
/*
752753
* POLLIN fired in body state after xapoll_stop (race).
753-
* nrf_recv already consumed bytes from the socket buffer
754+
* zsock_recv already consumed bytes from the socket buffer
754755
* into recv_buf and incremented total_received. Keep
755756
* recv_buf intact so the host can pull it; do NOT reset
756757
* recv_buf_len or the data is silently lost.
@@ -767,7 +768,7 @@ static void http_process_recv_body(struct http_request *req, struct sm_socket *s
767768
/* Finish if content-length satisfied, chunked EOF, or connection closing. */
768769
if (body_done ||
769770
(req->content_length > 0 && req->bytes_sent >= req->content_length) ||
770-
(events & NRF_POLLHUP)) {
771+
(events & ZSOCK_POLLHUP)) {
771772
http_finish_request(req);
772773
return;
773774
}
@@ -791,14 +792,14 @@ static void http_process_request(struct http_request *req, uint8_t events)
791792
req->state, events, k_uptime_get(), req->timeout_timestamp);
792793

793794
/* POLLERR/POLLNVAL are always fatal; POLLHUP is handled per-state below. */
794-
if (events & (NRF_POLLERR | NRF_POLLNVAL)) {
795+
if (events & (ZSOCK_POLLERR | ZSOCK_POLLNVAL)) {
795796
LOG_ERR("HTTP %d: Socket error (events=0x%x)", req->fd, events);
796797
http_fail_request(req);
797798
return;
798799
}
799800

800801
/* POLLHUP during sending means the server closed the connection unexpectedly. */
801-
if ((events & NRF_POLLHUP) && req->state == HTTP_STATE_SENDING_REQUEST) {
802+
if ((events & ZSOCK_POLLHUP) && req->state == HTTP_STATE_SENDING_REQUEST) {
802803
LOG_ERR("HTTP %d: Connection closed during send (events=0x%x)", req->fd,
803804
events);
804805
http_fail_request(req);
@@ -808,14 +809,14 @@ static void http_process_request(struct http_request *req, uint8_t events)
808809
switch (req->state) {
809810
case HTTP_STATE_SENDING_REQUEST:
810811
/* Handle writable socket */
811-
if (events & NRF_POLLOUT) {
812-
ret = nrf_send(req->fd, req->send_ptr, req->send_remaining,
813-
NRF_MSG_DONTWAIT);
812+
if (events & ZSOCK_POLLOUT) {
813+
ret = zsock_send(req->fd, req->send_ptr, req->send_remaining,
814+
MSG_DONTWAIT);
814815

815816
if (ret < 0) {
816817
if (errno == EAGAIN || errno == EWOULDBLOCK) {
817818
/* Need to wait for next POLLOUT */
818-
set_xapoll_events(sock, NRF_POLLOUT | NRF_POLLIN);
819+
set_xapoll_events(sock, ZSOCK_POLLOUT | ZSOCK_POLLIN);
819820
return;
820821
}
821822
LOG_ERR("Send failed: %d", errno);
@@ -830,10 +831,10 @@ static void http_process_request(struct http_request *req, uint8_t events)
830831
/* All headers sent, now wait for response */
831832
req->state = HTTP_STATE_RECEIVING_HEADERS;
832833
req->recv_buf_len = 0;
833-
set_xapoll_events(sock, NRF_POLLIN);
834+
set_xapoll_events(sock, ZSOCK_POLLIN);
834835
} else {
835836
/* More to send */
836-
set_xapoll_events(sock, NRF_POLLOUT | NRF_POLLIN);
837+
set_xapoll_events(sock, ZSOCK_POLLOUT | ZSOCK_POLLIN);
837838
}
838839
}
839840
break;
@@ -843,14 +844,14 @@ static void http_process_request(struct http_request *req, uint8_t events)
843844
* POLLHUP without POLLIN: closed before any response. When POLLIN
844845
* arrives at the same time, drain the socket buffer (e.g. Connection: close).
845846
*/
846-
if ((events & NRF_POLLHUP) && !(events & NRF_POLLIN)) {
847+
if ((events & ZSOCK_POLLHUP) && !(events & ZSOCK_POLLIN)) {
847848
LOG_ERR("HTTP %d: Connection closed before headers (POLLHUP)",
848849
req->fd);
849850
http_fail_request(req);
850851
return;
851852
}
852853

853-
if (!(events & NRF_POLLIN)) {
854+
if (!(events & ZSOCK_POLLIN)) {
854855
return;
855856
}
856857

@@ -871,13 +872,13 @@ static void http_process_request(struct http_request *req, uint8_t events)
871872

872873
case HTTP_STATE_RECEIVING_BODY:
873874
/* POLLHUP alone: server closed cleanly after sending body. */
874-
if ((events & NRF_POLLHUP) && !(events & NRF_POLLIN)) {
875+
if ((events & ZSOCK_POLLHUP) && !(events & ZSOCK_POLLIN)) {
875876
http_warn_incomplete_transfer(req);
876877
http_finish_request(req);
877878
return;
878879
}
879880

880-
if (!(events & NRF_POLLIN)) {
881+
if (!(events & ZSOCK_POLLIN)) {
881882
return;
882883
}
883884

@@ -948,7 +949,7 @@ static int http_send_request_headers(struct http_request *req)
948949
/* Send headers synchronously (blocking) */
949950
sent = 0;
950951
while (sent < ret) {
951-
n = nrf_send(req->fd, req->send_buf + sent, ret - sent, 0);
952+
n = zsock_send(req->fd, req->send_buf + sent, ret - sent, 0);
952953
if (n < 0) {
953954
return -errno;
954955
}
@@ -983,7 +984,7 @@ static int http_datamode_callback(uint8_t op, const uint8_t *data, int len, uint
983984
int sent = 0;
984985

985986
while (sent < len) {
986-
int ret = nrf_send(datamode_req->fd, data + sent, len - sent, 0);
987+
int ret = zsock_send(datamode_req->fd, data + sent, len - sent, 0);
987988

988989
if (ret < 0) {
989990
int err_code = -errno;
@@ -1026,7 +1027,7 @@ static int http_datamode_callback(uint8_t op, const uint8_t *data, int len, uint
10261027
datamode_req->recv_buf_len = 0;
10271028
datamode_req->timeout_timestamp =
10281029
k_uptime_get() + HTTP_RESPONSE_TIMEOUT_MS;
1029-
err = set_xapoll_events(sock, NRF_POLLIN);
1030+
err = set_xapoll_events(sock, ZSOCK_POLLIN);
10301031
if (err) {
10311032
LOG_ERR("Failed to arm XAPOLL: %d", err);
10321033
http_fail_request(datamode_req);
@@ -1339,7 +1340,7 @@ static int pull_data(int socket_fd, int pull_len)
13391340
}
13401341

13411342
/* Do one non-blocking recv and send to host */
1342-
ret = nrf_recv(req->fd, req->recv_buf, pull_len, NRF_MSG_DONTWAIT);
1343+
ret = zsock_recv(req->fd, req->recv_buf, pull_len, MSG_DONTWAIT);
13431344

13441345
if (ret < 0) {
13451346
if (errno == EAGAIN || errno == EWOULDBLOCK) {

app/src/sm_at_httpc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @brief Notify HTTP client of poll events (called from socket layer)
2121
*
2222
* @param fd Socket file descriptor
23-
* @param events Poll events (NRF_POLLIN, etc.)
23+
* @param events Poll events (ZSOCK_POLLIN, etc.)
2424
* @return true if HTTP client needs POLLIN re-armed after callback
2525
*/
2626
bool sm_at_httpc_poll_event(int fd, uint8_t events);

app/src/sm_at_icmp.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <stdio.h>
99
#include <string.h>
1010
#include <zephyr/net/socket.h>
11-
#include <nrf_socket.h>
1211
#include "sm_util.h"
1312
#include "sm_at_host.h"
1413

0 commit comments

Comments
 (0)