Lines Matching refs:spair
46 __net_socket struct spair { struct
60 K_MEM_SLAB_DEFINE_STATIC(spair_slab, sizeof(struct spair), CONFIG_NET_SOCKETPAIR_MAX * 2, argument
61 __alignof__(struct spair));
69 static inline bool sock_is_nonblock(const struct spair *spair) in sock_is_nonblock() argument
71 return !!(spair->flags & SPAIR_FLAG_NONBLOCK); in sock_is_nonblock()
75 static inline bool sock_is_connected(const struct spair *spair) in sock_is_connected() argument
77 const struct spair *remote = zvfs_get_fd_obj(spair->remote, in sock_is_connected()
89 static inline bool sock_is_eof(const struct spair *spair) in sock_is_eof() argument
91 return !sock_is_connected(spair); in sock_is_eof()
100 static inline size_t spair_write_avail(struct spair *spair) in spair_write_avail() argument
102 struct spair *const remote = zvfs_get_fd_obj(spair->remote, in spair_write_avail()
118 static inline size_t spair_read_avail(struct spair *spair) in spair_read_avail() argument
120 return k_pipe_read_avail(&spair->recv_q); in spair_read_avail()
161 static void spair_delete(struct spair *spair) in spair_delete() argument
164 struct spair *remote = NULL; in spair_delete()
167 if (spair == NULL) { in spair_delete()
171 if (spair->remote != -1) { in spair_delete()
172 remote = zvfs_get_fd_obj(spair->remote, in spair_delete()
189 spair->remote = -1; in spair_delete()
191 res = k_poll_signal_raise(&spair->writeable, SPAIR_SIG_CANCEL); in spair_delete()
199 memset(spair, 0, sizeof(*spair)); in spair_delete()
201 k_mem_slab_free(&spair_slab, (void *)spair); in spair_delete()
203 k_object_free(spair); in spair_delete()
205 k_free(spair); in spair_delete()
218 static struct spair *spair_new(void) in spair_new()
220 struct spair *spair; in spair_new() local
225 res = k_mem_slab_alloc(&spair_slab, (void **) &spair, K_NO_WAIT); in spair_new()
227 spair = NULL; in spair_new()
231 struct k_object *zo = k_object_create_dynamic(sizeof(*spair)); in spair_new()
234 spair = NULL; in spair_new()
236 spair = zo->name; in spair_new()
240 spair = k_malloc(sizeof(*spair)); in spair_new()
242 if (spair == NULL) { in spair_new()
246 memset(spair, 0, sizeof(*spair)); in spair_new()
249 spair->remote = -1; in spair_new()
250 spair->flags = SPAIR_FLAGS_DEFAULT; in spair_new()
252 k_sem_init(&spair->sem, 1, 1); in spair_new()
253 k_pipe_init(&spair->recv_q, spair->buf, sizeof(spair->buf)); in spair_new()
254 k_poll_signal_init(&spair->readable); in spair_new()
255 k_poll_signal_init(&spair->writeable); in spair_new()
258 res = k_poll_signal_raise(&spair->writeable, SPAIR_SIG_DATA); in spair_new()
261 spair->remote = zvfs_reserve_fd(); in spair_new()
262 if (spair->remote == -1) { in spair_new()
267 zvfs_finalize_typed_fd(spair->remote, spair, in spair_new()
273 spair_delete(spair); in spair_new()
274 spair = NULL; in spair_new()
277 return spair; in spair_new()
284 struct spair *obj[2] = {}; in z_impl_zsock_socketpair()
411 struct spair *const spair = (struct spair *)obj; in spair_write() local
412 struct spair *remote = NULL; in spair_write()
420 res = k_sem_take(&spair->sem, K_NO_WAIT); in spair_write()
421 is_nonblock = sock_is_nonblock(spair); in spair_write()
429 res = k_sem_take(&spair->sem, K_FOREVER); in spair_write()
435 is_nonblock = sock_is_nonblock(spair); in spair_write()
440 remote = zvfs_get_fd_obj(spair->remote, in spair_write()
466 avail = spair_write_avail(spair); in spair_write()
504 remote = zvfs_get_fd_obj(spair->remote, in spair_write()
557 if (spair_write_avail(spair) == 0) { in spair_write()
571 if (spair != NULL && have_local_sem) { in spair_write()
572 k_sem_give(&spair->sem); in spair_write()
621 struct spair *const spair = (struct spair *)obj; in spair_read() local
629 res = k_sem_take(&spair->sem, K_NO_WAIT); in spair_read()
630 is_nonblock = sock_is_nonblock(spair); in spair_read()
638 res = k_sem_take(&spair->sem, K_FOREVER); in spair_read()
644 is_nonblock = sock_is_nonblock(spair); in spair_read()
649 is_connected = sock_is_connected(spair); in spair_read()
650 avail = spair_read_avail(spair); in spair_read()
682 &spair->readable in spair_read()
686 k_sem_give(&spair->sem); in spair_read()
692 res = k_sem_take(&spair->sem, K_FOREVER); in spair_read()
697 k_poll_signal_check(&spair->readable, &signaled, in spair_read()
727 res = k_pipe_get(&spair->recv_q, (void *)buffer, count, &bytes_read, in spair_read()
731 if (spair_read_avail(spair) == 0 && !sock_is_eof(spair)) { in spair_read()
732 k_poll_signal_reset(&spair->readable); in spair_read()
736 res = k_poll_signal_raise(&spair->writeable, SPAIR_SIG_DATA); in spair_read()
744 if (spair != NULL && have_local_sem) { in spair_read()
745 k_sem_give(&spair->sem); in spair_read()
751 static int zsock_poll_prepare_ctx(struct spair *const spair, in zsock_poll_prepare_ctx() argument
758 struct spair *remote = NULL; in zsock_poll_prepare_ctx()
764 if (sock_is_eof(spair)) { in zsock_poll_prepare_ctx()
775 (*pev)->obj = &spair->readable; in zsock_poll_prepare_ctx()
781 if (!sock_is_connected(spair)) { in zsock_poll_prepare_ctx()
791 remote = zvfs_get_fd_obj(spair->remote, in zsock_poll_prepare_ctx()
825 static int zsock_poll_update_ctx(struct spair *const spair, in zsock_poll_update_ctx() argument
832 struct spair *remote = NULL; in zsock_poll_update_ctx()
836 if (!sock_is_connected(spair)) { in zsock_poll_update_ctx()
841 remote = zvfs_get_fd_obj(spair->remote, in zsock_poll_update_ctx()
854 if (spair_write_avail(spair) > 0) { in zsock_poll_update_ctx()
876 if (sock_is_eof(spair)) { in zsock_poll_update_ctx()
881 if (spair_read_avail(spair) > 0) { in zsock_poll_update_ctx()
888 k_poll_signal_check(&spair->readable, &signaled, &result); in zsock_poll_update_ctx()
920 struct spair *const spair = (struct spair *)obj; in spair_ioctl() local
922 if (spair == NULL) { in spair_ioctl()
932 res = k_sem_take(&spair->sem, K_FOREVER); in spair_ioctl()
939 if (sock_is_nonblock(spair)) { in spair_ioctl()
951 spair->flags |= SPAIR_FLAG_NONBLOCK; in spair_ioctl()
953 spair->flags &= ~SPAIR_FLAG_NONBLOCK; in spair_ioctl()
961 spair->flags |= SPAIR_FLAG_NONBLOCK; in spair_ioctl()
970 *nbytes = spair_read_avail(spair); in spair_ioctl()
1001 if (spair != NULL && have_local_sem) { in spair_ioctl()
1002 k_sem_give(&spair->sem); in spair_ioctl()
1071 struct spair *const spair = (struct spair *)obj; in spair_sendmsg() local
1073 if (spair == NULL || msg == NULL) { in spair_sendmsg()
1079 is_connected = sock_is_connected(spair); in spair_sendmsg()
1080 avail = is_connected ? spair_write_avail(spair) : 0; in spair_sendmsg()
1081 is_nonblock = sock_is_nonblock(spair); in spair_sendmsg()
1107 res = spair_write(spair, msg->msg_iov[i].iov_base, in spair_sendmsg()
1172 struct spair *const spair = (struct spair *)obj; in spair_close() local
1175 res = k_sem_take(&spair->sem, K_FOREVER); in spair_close()
1179 spair_delete(spair); in spair_close()