Skip to content

Commit c434614

Browse files
tokangasrlubos
authored andcommitted
samples: cellular: gnss: Remove SUPL POSIX API dependency
Removed dependency to POSIX API from SUPL assistance. Signed-off-by: Tommi Kangas <[email protected]>
1 parent 35d760d commit c434614

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

samples/cellular/gnss/src/assistance_supl.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static ssize_t supl_read(void *p_buff, size_t nbytes, void *user_data)
2727
{
2828
ARG_UNUSED(user_data);
2929

30-
ssize_t rc = recv(supl_fd, p_buff, nbytes, 0);
30+
ssize_t rc = zsock_recv(supl_fd, p_buff, nbytes, 0);
3131

3232
if (rc < 0 && (errno == EAGAIN)) {
3333
/* Return 0 to indicate a timeout. */
@@ -44,7 +44,7 @@ static ssize_t supl_write(const void *p_buff, size_t nbytes, void *user_data)
4444
{
4545
ARG_UNUSED(user_data);
4646

47-
return send(supl_fd, p_buff, nbytes, 0);
47+
return zsock_send(supl_fd, p_buff, nbytes, 0);
4848
}
4949

5050
static int inject_agnss_type(void *agnss, size_t agnss_size, uint16_t type, void *user_data)
@@ -90,17 +90,17 @@ static int open_supl_socket(void)
9090
{
9191
int err;
9292
char port[6];
93-
struct addrinfo *info;
93+
struct zsock_addrinfo *info;
9494

95-
struct addrinfo hints = {
95+
struct zsock_addrinfo hints = {
9696
.ai_flags = AI_NUMERICSERV,
9797
.ai_family = AF_UNSPEC, /* Both IPv4 and IPv6 addresses accepted. */
9898
.ai_socktype = SOCK_STREAM
9999
};
100100

101101
snprintf(port, sizeof(port), "%d", SUPL_SERVER_PORT);
102102

103-
err = getaddrinfo(SUPL_SERVER, port, &hints, &info);
103+
err = zsock_getaddrinfo(SUPL_SERVER, port, &hints, &info);
104104
if (err) {
105105
LOG_ERR("Failed to resolve hostname %s, error: %d", SUPL_SERVER, err);
106106

@@ -110,11 +110,11 @@ static int open_supl_socket(void)
110110
/* Not connected. */
111111
err = -1;
112112

113-
for (struct addrinfo *addr = info; addr != NULL; addr = addr->ai_next) {
113+
for (struct zsock_addrinfo *addr = info; addr != NULL; addr = addr->ai_next) {
114114
char ip[INET6_ADDRSTRLEN] = { 0 };
115115
struct sockaddr *const sa = addr->ai_addr;
116116

117-
supl_fd = socket(sa->sa_family, SOCK_STREAM, IPPROTO_TCP);
117+
supl_fd = zsock_socket(sa->sa_family, SOCK_STREAM, IPPROTO_TCP);
118118
if (supl_fd < 0) {
119119
LOG_ERR("Failed to create socket, errno %d", errno);
120120
goto cleanup;
@@ -126,21 +126,21 @@ static int open_supl_socket(void)
126126
.tv_usec = 0,
127127
};
128128

129-
err = setsockopt(supl_fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
129+
err = zsock_setsockopt(supl_fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
130130
if (err) {
131131
LOG_ERR("Failed to set socket timeout, errno %d", errno);
132132
goto cleanup;
133133
}
134134

135-
inet_ntop(sa->sa_family,
136-
(void *)&((struct sockaddr_in *)sa)->sin_addr,
137-
ip,
138-
INET6_ADDRSTRLEN);
135+
zsock_inet_ntop(sa->sa_family,
136+
(void *)&((struct sockaddr_in *)sa)->sin_addr,
137+
ip,
138+
INET6_ADDRSTRLEN);
139139
LOG_INF("Connecting to %s port %d", ip, SUPL_SERVER_PORT);
140140

141-
err = connect(supl_fd, sa, addr->ai_addrlen);
141+
err = zsock_connect(supl_fd, sa, addr->ai_addrlen);
142142
if (err) {
143-
close(supl_fd);
143+
zsock_close(supl_fd);
144144
supl_fd = -1;
145145

146146
/* Try the next address. */
@@ -152,13 +152,13 @@ static int open_supl_socket(void)
152152
}
153153

154154
cleanup:
155-
freeaddrinfo(info);
155+
zsock_freeaddrinfo(info);
156156

157157
if (err) {
158158
/* Unable to connect, close socket. */
159159
LOG_ERR("Could not connect to SUPL server");
160160
if (supl_fd > -1) {
161-
close(supl_fd);
161+
zsock_close(supl_fd);
162162
supl_fd = -1;
163163
}
164164
return -1;
@@ -169,7 +169,7 @@ static int open_supl_socket(void)
169169

170170
static void close_supl_socket(void)
171171
{
172-
if (close(supl_fd) < 0) {
172+
if (zsock_close(supl_fd) < 0) {
173173
LOG_ERR("Failed to close SUPL socket");
174174
}
175175
}

0 commit comments

Comments
 (0)