Lines Matching +full:remote +full:- +full:endpoint

4  * SPDX-License-Identifier: Apache-2.0
22 SPAIR_FLAG_NONBLOCK = (1 << 0), /**< socket is non-blocking */
28 * Socketpair endpoint structure
30 * This structure represents one half of a socketpair (an 'endpoint').
36 * endpoint) are said to be 'remote'.
39 * - each end of a socketpair owns a @a recv_q
40 * - since there is no write queue, data is either written or not
41 * - read and write operations may return partial transfers
42 * - read operations may block if the local @a recv_q is empty
43 * - write operations may block if the remote @a recv_q is full
44 * - each endpoint may be blocking or non-blocking
47 int remote; /**< the remote endpoint file descriptor */ member
50 struct k_pipe recv_q; /**< receive queue of local endpoint */
68 /** Determine if a @ref spair is in non-blocking mode */
71 return !!(spair->flags & SPAIR_FLAG_NONBLOCK); in sock_is_nonblock()
77 const struct spair *remote = zvfs_get_fd_obj(spair->remote, in sock_is_connected() local
80 if (remote == NULL) { in sock_is_connected()
88 /** Determine if a @ref spair has encountered end-of-file */
102 struct spair *const remote = zvfs_get_fd_obj(spair->remote, in spair_write_avail() local
105 if (remote == NULL) { in spair_write_avail()
109 return k_pipe_write_avail(&remote->recv_q); in spair_write_avail()
120 return k_pipe_read_avail(&spair->recv_q); in spair_read_avail()
123 /** Swap two 32-bit integers */
136 * This function deletes one endpoint of a socketpair.
139 * - we have a socketpair with two endpoints: A and B
140 * - we have two threads: T1 and T2
141 * - T1 operates on endpoint A
142 * - T2 operates on endpoint B
145 * when one endpoint is closed:
146 * -# T1 is blocked reading from A and T2 closes B
147 * T1 waits on A's write signal. T2 triggers the remote
149 * -# T1 is blocked writing to A and T2 closes B
153 * If the remote endpoint is already closed, the former operation does not
154 * take place. Otherwise, the @ref spair.remote of the local endpoint is
155 * set to -1.
159 * The memory associated with the local endpoint is cleared and freed.
164 struct spair *remote = NULL; in spair_delete() local
171 if (spair->remote != -1) { in spair_delete()
172 remote = zvfs_get_fd_obj(spair->remote, in spair_delete()
175 if (remote != NULL) { in spair_delete()
176 res = k_sem_take(&remote->sem, K_FOREVER); in spair_delete()
179 remote->remote = -1; in spair_delete()
180 res = k_poll_signal_raise(&remote->readable, in spair_delete()
189 spair->remote = -1; in spair_delete()
191 res = k_poll_signal_raise(&spair->writeable, SPAIR_SIG_CANCEL); in spair_delete()
194 if (remote != NULL && have_remote_sem) { in spair_delete()
195 k_sem_give(&remote->sem); in spair_delete()
213 * @ref spair.remote field initially.
215 * If both allocations are successful, then swap the @ref spair.remote
236 spair = zo->name; in spair_new()
237 zo->type = K_OBJ_NET_SOCKET; in spair_new()
248 /* initialize any non-zero default values */ 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()
290 res = -1; in z_impl_zsock_socketpair()
296 res = -1; in z_impl_zsock_socketpair()
302 res = -1; in z_impl_zsock_socketpair()
309 res = -1; in z_impl_zsock_socketpair()
316 res = -1; in z_impl_zsock_socketpair()
322 swap32(&obj[0]->remote, &obj[1]->remote); in z_impl_zsock_socketpair()
325 sv[i] = obj[i]->remote; in z_impl_zsock_socketpair()
326 k_sem_give(&obj[0]->sem); in z_impl_zsock_socketpair()
339 SYS_PORT_TRACING_OBJ_FUNC_EXIT(socket, socketpair, -1, -1, -errno); in z_impl_zsock_socketpair()
353 ret = -1; in z_vrfy_zsock_socketpair()
377 * non-blocking file descriptor, then -1 will be returned and @ref errno will
381 * set and there is insufficient space in the @em remote @ref spair.pipe.
384 * one of two possible results is received on the @em remote
387 * 1) @ref SPAIR_SIG_DATA - data has been read from the @em remote
390 * 2) @ref SPAIR_SIG_CANCEL - the @em remote socketpair endpoint was closed
393 * will return -1 and set @ref errno to @ref EPIPE.
400 * @return -1 on error, with @ref errno set appropriately.
412 struct spair *remote = NULL; in spair_write() local
416 res = -1; in spair_write()
420 res = k_sem_take(&spair->sem, K_NO_WAIT); in spair_write()
425 res = -1; in spair_write()
429 res = k_sem_take(&spair->sem, K_FOREVER); in spair_write()
431 errno = -res; in spair_write()
432 res = -1; in spair_write()
440 remote = zvfs_get_fd_obj(spair->remote, in spair_write()
443 if (remote == NULL) { in spair_write()
445 res = -1; in spair_write()
449 res = k_sem_take(&remote->sem, K_NO_WAIT); in spair_write()
453 res = -1; in spair_write()
456 res = k_sem_take(&remote->sem, K_FOREVER); in spair_write()
458 errno = -res; in spair_write()
459 res = -1; in spair_write()
471 res = -1; in spair_write()
480 res = -1; in spair_write()
484 for (int signaled = false, result = -1; !signaled; in spair_write()
485 result = -1) { in spair_write()
491 &remote->writeable), in spair_write()
494 k_sem_give(&remote->sem); in spair_write()
499 errno = -res; in spair_write()
500 res = -1; in spair_write()
504 remote = zvfs_get_fd_obj(spair->remote, in spair_write()
508 if (remote == NULL) { in spair_write()
510 res = -1; in spair_write()
514 res = k_sem_take(&remote->sem, K_FOREVER); in spair_write()
516 errno = -res; in spair_write()
517 res = -1; in spair_write()
523 k_poll_signal_check(&remote->writeable, &signaled, in spair_write()
536 res = -1; in spair_write()
553 res = k_pipe_put(&remote->recv_q, (void *)buffer, count, in spair_write()
558 k_poll_signal_reset(&remote->writeable); in spair_write()
561 res = k_poll_signal_raise(&remote->readable, SPAIR_SIG_DATA); in spair_write()
568 if (remote != NULL && have_remote_sem) { in spair_write()
569 k_sem_give(&remote->sem); in spair_write()
572 k_sem_give(&spair->sem); in spair_write()
587 * non-blocking file descriptor, then -1 will be returned and @ref errno will
597 * -# @ref SPAIR_SIG_DATA - data has been written to the @em local
600 * -# @ref SPAIR_SIG_CANCEL - read of the @em local @spair.pipe
602 * closed imminently). In this case, the function will return -1 and set
610 * @return -1 on error, with @ref errno set appropriately.
625 res = -1; in spair_read()
629 res = k_sem_take(&spair->sem, K_NO_WAIT); in spair_read()
634 res = -1; in spair_read()
638 res = k_sem_take(&spair->sem, K_FOREVER); in spair_read()
640 errno = -res; in spair_read()
641 res = -1; in spair_read()
661 res = -1; in spair_read()
671 res = -1; in spair_read()
675 for (int signaled = false, result = -1; !signaled; in spair_read()
676 result = -1) { 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()
710 res = -1; in spair_read()
727 res = k_pipe_get(&spair->recv_q, (void *)buffer, count, &bytes_read, 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()
745 k_sem_give(&spair->sem); in spair_read()
758 struct spair *remote = NULL; in zsock_poll_prepare_ctx() local
761 if (pfd->events & ZSOCK_POLLIN) { in zsock_poll_prepare_ctx()
763 /* Tell poll() to short-circuit wait */ in zsock_poll_prepare_ctx()
765 res = -EALREADY; in zsock_poll_prepare_ctx()
770 res = -ENOMEM; in zsock_poll_prepare_ctx()
775 (*pev)->obj = &spair->readable; in zsock_poll_prepare_ctx()
778 if (pfd->events & ZSOCK_POLLOUT) { in zsock_poll_prepare_ctx()
780 /* Tell poll() to short-circuit wait */ in zsock_poll_prepare_ctx()
782 res = -EALREADY; in zsock_poll_prepare_ctx()
787 res = -ENOMEM; in zsock_poll_prepare_ctx()
791 remote = zvfs_get_fd_obj(spair->remote, in zsock_poll_prepare_ctx()
795 __ASSERT(remote != NULL, "remote is NULL"); in zsock_poll_prepare_ctx()
797 res = k_sem_take(&remote->sem, K_FOREVER); in zsock_poll_prepare_ctx()
804 /* Wait until the recv queue on the remote end is no longer full */ in zsock_poll_prepare_ctx()
805 (*pev)->obj = &remote->writeable; in zsock_poll_prepare_ctx()
808 (*pev)->type = K_POLL_TYPE_SIGNAL; in zsock_poll_prepare_ctx()
809 (*pev)->mode = K_POLL_MODE_NOTIFY_ONLY; in zsock_poll_prepare_ctx()
810 (*pev)->state = K_POLL_STATE_NOT_READY; in zsock_poll_prepare_ctx()
818 if (remote != NULL && have_remote_sem) { in zsock_poll_prepare_ctx()
819 k_sem_give(&remote->sem); in zsock_poll_prepare_ctx()
832 struct spair *remote = NULL; in zsock_poll_update_ctx() local
835 if (pfd->events & ZSOCK_POLLOUT) { in zsock_poll_update_ctx()
837 pfd->revents |= ZSOCK_POLLHUP; in zsock_poll_update_ctx()
841 remote = zvfs_get_fd_obj(spair->remote, in zsock_poll_update_ctx()
844 __ASSERT(remote != NULL, "remote is NULL"); in zsock_poll_update_ctx()
846 res = k_sem_take(&remote->sem, K_FOREVER); in zsock_poll_update_ctx()
855 pfd->revents |= ZSOCK_POLLOUT; in zsock_poll_update_ctx()
861 k_poll_signal_check(&remote->writeable, &signaled, &result); in zsock_poll_update_ctx()
869 pfd->revents |= ZSOCK_POLLHUP; in zsock_poll_update_ctx()
875 if (pfd->events & ZSOCK_POLLIN) { in zsock_poll_update_ctx()
877 pfd->revents |= ZSOCK_POLLIN; in zsock_poll_update_ctx()
882 pfd->revents |= ZSOCK_POLLIN; in zsock_poll_update_ctx()
888 k_poll_signal_check(&spair->readable, &signaled, &result); in zsock_poll_update_ctx()
896 pfd->revents |= ZSOCK_POLLIN; in zsock_poll_update_ctx()
905 if (remote != NULL && have_remote_sem) { in zsock_poll_update_ctx()
906 k_sem_give(&remote->sem); in zsock_poll_update_ctx()
924 res = -1; in spair_ioctl()
929 * function call requires the remote sem, it must acquire and free the in spair_ioctl()
930 * remote sem. in spair_ioctl()
932 res = k_sem_take(&spair->sem, K_FOREVER); 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()
995 res = -1; in spair_ioctl()
1002 k_sem_give(&spair->sem); in spair_ioctl()
1016 return -1; in spair_bind()
1027 return -1; in spair_connect()
1036 return -1; in spair_listen()
1047 return -1; in spair_accept()
1075 res = -1; in spair_sendmsg()
1083 for (size_t i = 0; i < msg->msg_iovlen; ++i) { in spair_sendmsg()
1084 /* check & msg->msg_iov[i]? */ in spair_sendmsg()
1085 /* check & msg->msg_iov[i].iov_base? */ in spair_sendmsg()
1086 len += msg->msg_iov[i].iov_len; in spair_sendmsg()
1091 res = -1; in spair_sendmsg()
1102 res = -1; in spair_sendmsg()
1106 for (size_t i = 0; i < msg->msg_iovlen; ++i) { in spair_sendmsg()
1107 res = spair_write(spair, msg->msg_iov[i].iov_base, in spair_sendmsg()
1108 msg->msg_iov[i].iov_len); in spair_sendmsg()
1109 if (res == -1) { in spair_sendmsg()
1154 return -1; in spair_getsockopt()
1167 return -1; in spair_setsockopt()
1175 res = k_sem_take(&spair->sem, K_FOREVER); in spair_close()
1178 /* disconnect the remote endpoint */ in spair_close()