xine-lib: xine-lib-1.2.13/include/xine/io_helper.h Source File

xine-lib 1.2.13-20230125hg15249

io_helper.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2000-2021 the xine project,
3 *
4 * This file is part of xine, a free video player.
5 *
6 * xine is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * xine is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * abortable i/o helper functions
21 */
22
23#ifndef IO_HELPER_H
24#define IO_HELPER_H
25
26#include "xine_internal.h"
27
28
29/* select states */
30#define XIO_READ_READY 1
31#define XIO_WRITE_READY 2
32
33/* xine select return codes */
34#define XIO_READY 0
35#define XIO_ERROR 1
36#define XIO_ABORTED 2
37#define XIO_TIMEOUT 3
38
39
40/*
41 * Waits for a file descriptor/socket to change status.
42 *
43 * network input plugins should use this function in order to
44 * not freeze the engine.
45 *
46 * params :
47 * stream needed for aborting and reporting errors but may be NULL
48 * fd file/socket descriptor or -1 (just wait)
49 * state XIO_READ_READY, XIO_WRITE_READY or 0 (just wait)
50 * timeout_msec timeout in milliseconds
51 *
52 * Engine seek/stop can abort this function if stream != NULL.
53 *
54 * return value :
55 * XIO_READY the file descriptor is ready for cmd
56 * XIO_ERROR an i/o error occured
57 * XIO_ABORTED command aborted by an other thread
58 * XIO_TIMEOUT the file descriptor is not ready after timeout_msec milliseconds
59 */
60int _x_io_select (xine_stream_t *stream, int fd, int state, int timeout_msec) XINE_PROTECTED XINE_USED;
61
62
63/*
64 * open a tcp connection
65 *
66 * params :
67 * stream needed for reporting errors but may be NULL
68 * host address of target
69 * port port on target
70 *
71 * returns a socket descriptor or -1 if an error occured
72 */
73int _x_io_tcp_connect(xine_stream_t *stream, const char *host, int port) XINE_PROTECTED XINE_USED;
74
75/* connect and handshake. */
76 typedef enum {
77 /* return success. */
78 XIO_HANDSHAKE_OK = 1,
79 /* reopen same target, and try a different handshake (eg with/without tls). */
80 XIO_HANDSHAKE_TRY_SAME = 2,
81 /* try next target, if any. */
82 XIO_HANDSHAKE_TRY_NEXT = 3,
83 /* return failure (eg when handshake has hit a -1 EINTR). */
84 XIO_HANDSHAKE_INTR = 4
85} xio_handshake_status_t;
86/* use _x_io_* () below. */
87 typedef xio_handshake_status_t (xio_handshake_cb_t)(void *userdata, int fd);
88/* like _x_io_tcp_connect (). */
89int _x_io_tcp_handshake_connect (xine_stream_t *stream, const char *host, int port,
90 xio_handshake_cb_t *handshake_cb, void *userdata) XINE_PROTECTED XINE_USED;
91
92/*
93 * wait for finish connection
94 *
95 * params :
96 * stream needed for aborting and reporting errors but may be NULL
97 * fd socket descriptor
98 * timeout_msec timeout in milliseconds
99 *
100 * return value:
101 * XIO_READY host respond, the socket is ready for cmd
102 * XIO_ERROR an i/o error occured
103 * XIO_ABORTED command aborted by an other thread
104 * XIO_TIMEOUT the file descriptor is not ready after timeout
105 */
106int _x_io_tcp_connect_finish(xine_stream_t *stream, int fd, int timeout_msec) XINE_PROTECTED XINE_USED;
107
108/* The next 5 read/write functions will try to transfer todo/min bytes unless
109 * - the end of stream is reached (0), or
110 * - no data is available for user network timeout seconds (-1 ETIMEDOUT), or
111 * - an io error hits (-1 Exxx), or
112 * - xine engine wants to seek/stop (-1 EINTR).
113 * _x_io_tcp_part_read (stream, s, buf, 0, len) may also yield (-1 EAGAIN), and will never wait.
114 * network input plugins should use these functions in order not to freeze the engine.
115 * "off_t" is just there for historical reasons, "(s)size_t" should be enough.
116 */
117off_t _x_io_tcp_read (xine_stream_t *stream, int s, void *buf, off_t todo) XINE_PROTECTED XINE_USED;
118/* like _x_io_tcp_read () but:
119 * 1. wait until we have at least min bytes, then
120 * 2. return up to max bytes that are already there. */
121ssize_t _x_io_tcp_part_read (xine_stream_t *stream, int s, void *buf, size_t min, size_t max) XINE_PROTECTED XINE_USED;
122off_t _x_io_tcp_write (xine_stream_t *stream, int s, const void *buf, off_t todo) XINE_PROTECTED XINE_USED;
123off_t _x_io_file_read (xine_stream_t *stream, int fd, void *buf, off_t todo) XINE_PROTECTED XINE_USED;
124off_t _x_io_file_write (xine_stream_t *stream, int fd, const void *buf, off_t todo) XINE_PROTECTED XINE_USED;
125
126/* XXX this is slow.
127 * read a string from socket, return string length (same as strlen)
128 * the string is always '\0' terminated but given buffer size is never exceeded
129 * that is, _x_io_tcp_read_line(,,,X) <= (X-1) ; X > 0
130 */
131int _x_io_tcp_read_line(xine_stream_t *stream, int sock, char *str, int size) XINE_PROTECTED XINE_USED;
132
133/*
134 * Close socket
135 */
136int _x_io_tcp_close(xine_stream_t *stream, int fd) XINE_PROTECTED;
137
138#endif
XINE_USED
#define XINE_USED
Definition attributes.h:60
XINE_PROTECTED
#define XINE_PROTECTED
Definition attributes.h:75
_x_io_tcp_connect
int _x_io_tcp_connect(xine_stream_t *stream, const char *host, int port)
Definition io_helper.c:159
_x_io_tcp_write
off_t _x_io_tcp_write(xine_stream_t *stream, int s, const void *buf, off_t todo)
Definition io_helper.c:631
_x_io_tcp_connect_finish
int _x_io_tcp_connect_finish(xine_stream_t *stream, int fd, int timeout_msec)
Definition io_helper.c:502
xio_handshake_cb_t
xio_handshake_status_t xio_handshake_cb_t(void *userdata, int fd)
Definition io_helper.h:87
_x_io_tcp_close
int _x_io_tcp_close(xine_stream_t *stream, int fd)
Definition io_helper.c:764
_x_io_tcp_read
off_t _x_io_tcp_read(xine_stream_t *stream, int s, void *buf, off_t todo)
Definition io_helper.c:548
_x_io_tcp_handshake_connect
int _x_io_tcp_handshake_connect(xine_stream_t *stream, const char *host, int port, xio_handshake_cb_t *handshake_cb, void *userdata)
Definition io_helper.c:163
_x_io_tcp_part_read
ssize_t _x_io_tcp_part_read(xine_stream_t *stream, int s, void *buf, size_t min, size_t max)
Definition io_helper.c:582
_x_io_select
int _x_io_select(xine_stream_t *stream, int fd, int state, int timeout_msec)
Definition io_helper.c:376
xio_handshake_status_t
xio_handshake_status_t
Definition io_helper.h:76
XIO_HANDSHAKE_OK
@ XIO_HANDSHAKE_OK
Definition io_helper.h:78
XIO_HANDSHAKE_TRY_NEXT
@ XIO_HANDSHAKE_TRY_NEXT
Definition io_helper.h:82
XIO_HANDSHAKE_INTR
@ XIO_HANDSHAKE_INTR
Definition io_helper.h:84
XIO_HANDSHAKE_TRY_SAME
@ XIO_HANDSHAKE_TRY_SAME
Definition io_helper.h:80
_x_io_tcp_read_line
int _x_io_tcp_read_line(xine_stream_t *stream, int sock, char *str, int size)
Definition io_helper.c:738
_x_io_file_read
off_t _x_io_file_read(xine_stream_t *stream, int fd, void *buf, off_t todo)
Definition io_helper.c:665
_x_io_file_write
off_t _x_io_file_write(xine_stream_t *stream, int fd, const void *buf, off_t todo)
Definition io_helper.c:699
xine_stream_s
Definition xine_internal.h:123
xine_internal.h