Skip to content

Commit c39291b

Browse files
Mattemagikernkartben
authored andcommitted
net: socketpair to use ring_buffer instead of k_pipe
Replaced the k_pipe-based implementation in sockpair with ring_buffer based implementation instead. The move to ring_buffer is done to avoid overhead of k_pipe and to align with the new k_pipe API. This does not pose any added risk to concurrency as the read and write functions are protected by semaphores for both spairs. Signed-off-by: Måns Ansgariusson <[email protected]>
1 parent 3de3402 commit c39291b

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

subsys/net/lib/sockets/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ config NET_SOCKETS_CAN_RECEIVERS
324324

325325
config NET_SOCKETPAIR
326326
bool "Support for socketpair"
327-
select PIPES
328327
help
329328
Communicate over a pair of connected, unnamed UNIX domain sockets.
330329

subsys/net/lib/sockets/socketpair.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ __net_socket struct spair {
4747
int remote; /**< the remote endpoint file descriptor */
4848
uint32_t flags; /**< status and option bits */
4949
struct k_sem sem; /**< semaphore for exclusive structure access */
50-
struct k_pipe recv_q; /**< receive queue of local endpoint */
50+
struct ring_buf recv_q;
5151
/** indicates local @a recv_q isn't empty */
5252
struct k_poll_signal readable;
5353
/** indicates local @a recv_q isn't full */
@@ -106,7 +106,7 @@ static inline size_t spair_write_avail(struct spair *spair)
106106
return 0;
107107
}
108108

109-
return k_pipe_write_avail(&remote->recv_q);
109+
return ring_buf_space_get(&remote->recv_q);
110110
}
111111

112112
/**
@@ -117,7 +117,7 @@ static inline size_t spair_write_avail(struct spair *spair)
117117
*/
118118
static inline size_t spair_read_avail(struct spair *spair)
119119
{
120-
return k_pipe_read_avail(&spair->recv_q);
120+
return ring_buf_size_get(&spair->recv_q);
121121
}
122122

123123
/** Swap two 32-bit integers */
@@ -250,7 +250,7 @@ static struct spair *spair_new(void)
250250
spair->flags = SPAIR_FLAGS_DEFAULT;
251251

252252
k_sem_init(&spair->sem, 1, 1);
253-
k_pipe_init(&spair->recv_q, spair->buf, sizeof(spair->buf));
253+
ring_buf_init(&spair->recv_q, sizeof(spair->buf), spair->buf);
254254
k_poll_signal_init(&spair->readable);
255255
k_poll_signal_init(&spair->writeable);
256256

@@ -550,10 +550,7 @@ static ssize_t spair_write(void *obj, const void *buffer, size_t count)
550550
}
551551
}
552552

553-
res = k_pipe_put(&remote->recv_q, (void *)buffer, count,
554-
&bytes_written, 1, K_NO_WAIT);
555-
__ASSERT(res == 0, "k_pipe_put() failed: %d", res);
556-
553+
bytes_written = ring_buf_put(&remote->recv_q, (void *)buffer, count);
557554
if (spair_write_avail(spair) == 0) {
558555
k_poll_signal_reset(&remote->writeable);
559556
}
@@ -724,10 +721,7 @@ static ssize_t spair_read(void *obj, void *buffer, size_t count)
724721
}
725722
}
726723

727-
res = k_pipe_get(&spair->recv_q, (void *)buffer, count, &bytes_read,
728-
1, K_NO_WAIT);
729-
__ASSERT(res == 0, "k_pipe_get() failed: %d", res);
730-
724+
bytes_read = ring_buf_get(&spair->recv_q, (void *)buffer, count);
731725
if (spair_read_avail(spair) == 0 && !sock_is_eof(spair)) {
732726
k_poll_signal_reset(&spair->readable);
733727
}

0 commit comments

Comments
 (0)