xine-lib  1.2.9
io_helper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000-2017 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
49  * state XIO_READ_READY, XIO_WRITE_READY
50  * timeout_sec timeout in seconds
51  *
52  * An other thread can abort this function if stream != NULL by setting
53  * stream->demux_action_pending.
54  *
55  * return value :
56  * XIO_READY the file descriptor is ready for cmd
57  * XIO_ERROR an i/o error occured
58  * XIO_ABORTED command aborted by an other thread
59  * XIO_TIMEOUT the file descriptor is not ready after timeout_msec milliseconds
60  */
61 int _x_io_select (xine_stream_t *stream, int fd, int state, int timeout_msec) XINE_PROTECTED XINE_USED;
62 
63 
64 /*
65  * open a tcp connection
66  *
67  * params :
68  * stream needed for reporting errors but may be NULL
69  * host address of target
70  * port port on target
71  *
72  * returns a socket descriptor or -1 if an error occured
73  */
74 int _x_io_tcp_connect(xine_stream_t *stream, const char *host, int port) XINE_PROTECTED XINE_USED;
75 
76 /*
77  * wait for finish connection
78  *
79  * params :
80  * stream needed for aborting and reporting errors but may be NULL
81  * fd socket descriptor
82  * timeout_msec timeout in milliseconds
83  *
84  * return value:
85  * XIO_READY host respond, the socket is ready for cmd
86  * XIO_ERROR an i/o error occured
87  * XIO_ABORTED command aborted by an other thread
88  * XIO_TIMEOUT the file descriptor is not ready after timeout
89  */
90 int _x_io_tcp_connect_finish(xine_stream_t *stream, int fd, int timeout_msec) XINE_PROTECTED XINE_USED;
91 
92 /*
93  * read from tcp socket checking demux_action_pending
94  *
95  * network input plugins should use this function in order to
96  * not freeze the engine.
97  *
98  * aborts with zero if no data is available and *abort is set
99  */
100 off_t _x_io_tcp_read (xine_stream_t *stream, int s, void *buf, off_t todo) XINE_PROTECTED XINE_USED;
101 
102 
103 /*
104  * write to a tcp socket checking demux_action_pending
105  *
106  * network input plugins should use this function in order to
107  * not freeze the engine.
108  *
109  * aborts with zero if no data is available and *abort is set
110  */
111 off_t _x_io_tcp_write (xine_stream_t *stream, int s, const void *buf, off_t todo) XINE_PROTECTED XINE_USED;
112 
113 /*
114  * read from a file descriptor checking demux_action_pending
115  *
116  * the fifo input plugin should use this function in order to
117  * not freeze the engine.
118  *
119  * aborts with zero if no data is available and *abort is set
120  */
121 off_t _x_io_file_read (xine_stream_t *stream, int fd, void *buf, off_t todo) XINE_PROTECTED XINE_USED;
122 
123 
124 /*
125  * write to a file descriptor checking demux_action_pending
126  *
127  * the fifo input plugin should use this function in order to
128  * not freeze the engine.
129  *
130  * aborts with zero if *abort is set
131  */
132 off_t _x_io_file_write (xine_stream_t *stream, int fd, const void *buf, off_t todo) XINE_PROTECTED XINE_USED;
133 
134 /*
135  * read a string from socket, return string length (same as strlen)
136  * the string is always '\0' terminated but given buffer size is never exceeded
137  * that is, _x_io_tcp_read_line(,,,X) <= (X-1) ; X > 0
138  */
139 int _x_io_tcp_read_line(xine_stream_t *stream, int sock, char *str, int size) XINE_PROTECTED XINE_USED;
140 
141 #endif
int _x_io_select(xine_stream_t *stream, int fd, int state, int timeout_msec) XINE_USED
Definition: io_helper.c:228
off_t _x_io_tcp_read(xine_stream_t *stream, int s, void *buf, off_t todo) XINE_USED
Definition: io_helper.c:435
Definition: xine_internal.h:210
#define XINE_USED
Definition: attributes.h:58
#define XINE_PROTECTED
Definition: attributes.h:73
off_t _x_io_file_write(xine_stream_t *stream, int fd, const void *buf, off_t todo) XINE_USED
Definition: io_helper.c:447
int _x_io_tcp_connect_finish(xine_stream_t *stream, int fd, int timeout_msec) XINE_USED
Definition: io_helper.c:321
int _x_io_tcp_read_line(xine_stream_t *stream, int sock, char *str, int size) XINE_USED
Definition: io_helper.c:456
off_t _x_io_tcp_write(xine_stream_t *stream, int s, const void *buf, off_t todo) XINE_USED
Definition: io_helper.c:439
int _x_io_tcp_connect(xine_stream_t *stream, const char *host, int port) XINE_USED
Definition: io_helper.c:130
off_t _x_io_file_read(xine_stream_t *stream, int fd, void *buf, off_t todo) XINE_USED
Definition: io_helper.c:443