Lines Matching refs:io_ctx
85 struct iio_network_io_context io_ctx; member
93 struct iio_network_io_context io_ctx; member
121 static int setup_cancel(struct iio_network_io_context *io_ctx) in setup_cancel() argument
123 io_ctx->events[0] = WSACreateEvent(); in setup_cancel()
124 if (io_ctx->events[0] == WSA_INVALID_EVENT) in setup_cancel()
127 io_ctx->events[1] = WSACreateEvent(); in setup_cancel()
128 if (io_ctx->events[1] == WSA_INVALID_EVENT) { in setup_cancel()
129 WSACloseEvent(io_ctx->events[0]); in setup_cancel()
136 static void cleanup_cancel(struct iio_network_io_context *io_ctx) in cleanup_cancel() argument
138 WSACloseEvent(io_ctx->events[0]); in cleanup_cancel()
139 WSACloseEvent(io_ctx->events[1]); in cleanup_cancel()
142 static void do_cancel(struct iio_network_io_context *io_ctx) in do_cancel() argument
144 WSASetEvent(io_ctx->events[1]); in do_cancel()
147 static int wait_cancellable(struct iio_network_io_context *io_ctx, bool read) in wait_cancellable() argument
152 if (!io_ctx->cancellable) in wait_cancellable()
160 WSAEventSelect(io_ctx->fd, NULL, 0); in wait_cancellable()
161 WSAResetEvent(io_ctx->events[0]); in wait_cancellable()
162 WSAEventSelect(io_ctx->fd, io_ctx->events[0], wsa_events); in wait_cancellable()
164 ret = WSAWaitForMultipleEvents(2, io_ctx->events, FALSE, in wait_cancellable()
218 static int create_cancel_fd(struct iio_network_io_context *io_ctx) in create_cancel_fd() argument
220 io_ctx->cancel_fd[0] = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); in create_cancel_fd()
221 if (io_ctx->cancel_fd[0] < 0) in create_cancel_fd()
226 static void cleanup_cancel(struct iio_network_io_context *io_ctx) in cleanup_cancel() argument
228 close(io_ctx->cancel_fd[0]); in cleanup_cancel()
235 static int create_cancel_fd(struct iio_network_io_context *io_ctx) in create_cancel_fd() argument
240 ret = pipe2(io_ctx->cancel_fd, O_CLOEXEC | O_NONBLOCK); in create_cancel_fd()
244 ret = pipe(io_ctx->cancel_fd); in create_cancel_fd()
247 ret = set_blocking_mode(io_ctx->cancel_fd[0], false); in create_cancel_fd()
250 ret = set_blocking_mode(io_ctx->cancel_fd[1], false); in create_cancel_fd()
256 close(io_ctx->cancel_fd[0]); in create_cancel_fd()
257 close(io_ctx->cancel_fd[1]); in create_cancel_fd()
261 static void cleanup_cancel(struct iio_network_io_context *io_ctx) in cleanup_cancel() argument
263 close(io_ctx->cancel_fd[0]); in cleanup_cancel()
264 close(io_ctx->cancel_fd[1]); in cleanup_cancel()
271 static int setup_cancel(struct iio_network_io_context *io_ctx) in setup_cancel() argument
275 ret = set_blocking_mode(io_ctx->fd, false); in setup_cancel()
279 return create_cancel_fd(io_ctx); in setup_cancel()
282 static void do_cancel(struct iio_network_io_context *io_ctx) in do_cancel() argument
287 ret = write(io_ctx->cancel_fd[CANCEL_WR_FD], &event, sizeof(event)); in do_cancel()
296 static int wait_cancellable(struct iio_network_io_context *io_ctx, bool read) in wait_cancellable() argument
301 if (!io_ctx->cancellable) in wait_cancellable()
306 pfd[0].fd = io_ctx->fd; in wait_cancellable()
311 pfd[1].fd = io_ctx->cancel_fd[0]; in wait_cancellable()
317 if (io_ctx->timeout_ms > 0) in wait_cancellable()
318 timeout_ms = (int) io_ctx->timeout_ms; in wait_cancellable()
469 static ssize_t network_recv(struct iio_network_io_context *io_ctx, in network_recv() argument
476 ret = wait_cancellable(io_ctx, true); in network_recv()
480 ret = recv(io_ctx->fd, data, (int) len, flags); in network_recv()
488 if (io_ctx->cancellable) in network_recv()
499 static ssize_t network_send(struct iio_network_io_context *io_ctx, in network_send() argument
506 ret = wait_cancellable(io_ctx, false); in network_send()
510 ret = send(io_ctx->fd, data, (int) len, flags); in network_send()
518 if (io_ctx->cancellable) in network_send()
530 static ssize_t write_all(struct iio_network_io_context *io_ctx, in write_all() argument
535 ssize_t ret = network_send(io_ctx, (const void *) ptr, len, 0); in write_all()
544 static ssize_t write_command(struct iio_network_io_context *io_ctx, in write_command() argument
550 ret = write_all(io_ctx, cmd, strlen(cmd)); in write_command()
563 do_cancel(&ppdata->io_ctx); in network_cancel()
565 ppdata->io_ctx.cancelled = true; in network_cancel()
734 if (ppdata->io_ctx.fd >= 0) in network_open()
741 ppdata->io_ctx.fd = ret; in network_open()
742 ppdata->io_ctx.cancelled = false; in network_open()
743 ppdata->io_ctx.cancellable = false; in network_open()
744 ppdata->io_ctx.timeout_ms = DEFAULT_TIMEOUT_MS; in network_open()
747 &ppdata->io_ctx, dev, samples_count, cyclic); in network_open()
751 ret = setup_cancel(&ppdata->io_ctx); in network_open()
755 set_socket_timeout(ppdata->io_ctx.fd, pdata->io_ctx.timeout_ms); in network_open()
757 ppdata->io_ctx.timeout_ms = pdata->io_ctx.timeout_ms; in network_open()
758 ppdata->io_ctx.cancellable = true; in network_open()
771 close(ppdata->io_ctx.fd); in network_open()
772 ppdata->io_ctx.fd = -1; in network_open()
785 if (pdata->io_ctx.fd >= 0) { in network_close()
786 if (!pdata->io_ctx.cancelled) { in network_close()
789 &pdata->io_ctx, dev); in network_close()
791 write_command(&pdata->io_ctx, "\r\nEXIT\r\n"); in network_close()
796 cleanup_cancel(&pdata->io_ctx); in network_close()
797 close(pdata->io_ctx.fd); in network_close()
798 pdata->io_ctx.fd = -1; in network_close()
824 &pdata->io_ctx, dev, dst, len, mask, words); in network_read()
838 &pdata->io_ctx, dev, src, len); in network_write()
846 static ssize_t read_all(struct iio_network_io_context *io_ctx, in read_all() argument
851 ssize_t ret = network_recv(io_ctx, (void *) ptr, len, 0); in read_all()
860 static int read_integer(struct iio_network_io_context *io_ctx, long *val) in read_integer() argument
868 ret = read_all(io_ctx, buf + i, 1); in read_integer()
888 static ssize_t network_read_mask(struct iio_network_io_context *io_ctx, in network_read_mask() argument
894 ret = read_integer(io_ctx, &read_len); in network_read_mask()
906 ret = read_all(io_ctx, buf, 8); in network_read_mask()
918 ssize_t nb = read_all(io_ctx, &c, 1); in network_read_mask()
926 static ssize_t read_error_code(struct iio_network_io_context *io_ctx) in read_error_code() argument
946 ssize_t ret = read_integer(io_ctx, &resp); in read_error_code()
962 ssize_t ret = read_error_code(&pdata->io_ctx); in write_rwbuf_command()
969 return write_command(&pdata->io_ctx, cmd); in write_rwbuf_command()
984 fd_in = pdata->io_ctx.fd; in network_do_splice()
988 fd_out = pdata->io_ctx.fd; in network_do_splice()
992 ret = wait_cancellable(&pdata->io_ctx, read); in network_do_splice()
1111 ret = network_read_mask(&pdata->io_ctx, mask, words); in network_get_buffer()
1156 &pdata->io_ctx, dev, NULL, attr, dst, len, type); in network_read_dev_attr()
1165 &pdata->io_ctx, dev, NULL, attr, src, len, type); in network_write_dev_attr()
1174 &pdata->io_ctx, chn->dev, chn, attr, dst, len, false); in network_read_chn_attr()
1183 &pdata->io_ctx, chn->dev, chn, attr, src, len, false); in network_write_chn_attr()
1192 &pdata->io_ctx, dev, trigger); in network_get_trigger()
1201 &pdata->io_ctx, dev, trigger); in network_set_trigger()
1210 write_command(&pdata->io_ctx, "\r\nEXIT\r\n"); in network_shutdown()
1211 close(pdata->io_ctx.fd); in network_shutdown()
1235 &ctx->pdata->io_ctx, major, minor, git_tag); in network_get_version()
1248 int ret, fd = pdata->io_ctx.fd; in network_set_timeout()
1255 &pdata->io_ctx, remote_timeout); in network_set_timeout()
1257 pdata->io_ctx.timeout_ms = timeout; in network_set_timeout()
1273 &pdata->io_ctx, dev, nb_blocks); in network_set_kernel_buffers_count()
1309 struct iio_network_io_context *io_ctx = io_data; in network_write_data() local
1311 return network_send(io_ctx, src, len, 0); in network_write_data()
1317 struct iio_network_io_context *io_ctx = io_data; in network_read_data() local
1319 return network_recv(io_ctx, dst, len, 0); in network_read_data()
1328 struct iio_network_io_context *io_ctx = io_data; in network_read_line() local
1335 ret = network_recv(io_ctx, dst, len, MSG_PEEK); in network_read_line()
1354 ret = network_recv(io_ctx, NULL, to_trunc, MSG_TRUNC); in network_read_line()
1356 ret = network_recv(io_ctx, dst - ret, to_trunc, 0); in network_read_line()
1400 static bool msg_trunc_supported(struct iio_network_io_context *io_ctx) in msg_trunc_supported() argument
1404 ret = network_recv(io_ctx, NULL, 0, MSG_TRUNC | MSG_DONTWAIT); in msg_trunc_supported()
1409 static bool msg_trunc_supported(struct iio_network_io_context *io_ctx) in msg_trunc_supported() argument
1486 pdata->io_ctx.fd = fd; in network_create_context()
1488 pdata->io_ctx.timeout_ms = DEFAULT_TIMEOUT_MS; in network_create_context()
1499 pdata->msg_trunc_supported = msg_trunc_supported(&pdata->io_ctx); in network_create_context()
1509 ctx = iiod_client_create_context(pdata->iiod_client, &pdata->io_ctx); in network_create_context()
1574 dev->pdata->io_ctx.fd = -1; in network_create_context()
1575 dev->pdata->io_ctx.timeout_ms = DEFAULT_TIMEOUT_MS; in network_create_context()
1605 iiod_client_set_timeout(pdata->iiod_client, &pdata->io_ctx, in network_create_context()