forked from Android-Apps/polipo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.h
161 lines (136 loc) · 5.05 KB
/
io.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
Copyright (c) 2003-2006 by Juliusz Chroboczek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* request->operation */
#define IO_READ 0
#define IO_WRITE 1
#define IO_MASK 0xFF
/* Do not initiate operation now -- wait for the poll loop. */
#define IO_NOTNOW 0x100
/* Call the progress handler once if no data arrives immediately. */
#define IO_IMMEDIATE 0x200
/* Emit a chunk length before every write operation */
#define IO_CHUNKED 0x400
/* Emit a zero-length chunk at the end if chunked */
#define IO_END 0x800
/* Internal -- header is really buf3 */
#define IO_BUF3 0x1000
/* Internal -- header is really buf_location */
#define IO_BUF_LOCATION 0x2000
typedef struct _StreamRequest {
short operation;
short fd;
int offset;
int len;
int len2;
union {
struct {
int hlen;
char *header;
} h;
struct {
int len3;
char *buf3;
} b;
struct {
char **buf_location;
} l;
} u;
char *buf;
char *buf2;
int (*handler)(int, FdEventHandlerPtr, struct _StreamRequest*);
void *data;
} StreamRequestRec, *StreamRequestPtr;
typedef struct _ConnectRequest {
int fd;
int af;
struct _Atom *addr;
int firstindex;
int index;
int port;
int (*handler)(int, FdEventHandlerPtr, struct _ConnectRequest*);
void *data;
} ConnectRequestRec, *ConnectRequestPtr;
typedef struct _AcceptRequest {
int fd;
int (*handler)(int, FdEventHandlerPtr, struct _AcceptRequest*);
void *data;
} AcceptRequestRec, *AcceptRequestPtr;
void preinitIo();
void initIo();
FdEventHandlerPtr
do_stream(int operation, int fd, int offset, char *buf, int len,
int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr),
void *data);
FdEventHandlerPtr
do_stream_h(int operation, int fd, int offset,
char *header, int hlen, char *buf, int len,
int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr),
void *data);
FdEventHandlerPtr
do_stream_2(int operation, int fd, int offset,
char *buf, int len, char *buf2, int len2,
int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr),
void *data);
FdEventHandlerPtr
do_stream_3(int operation, int fd, int offset,
char *buf, int len, char *buf2, int len2, char *buf3, int len3,
int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr),
void *data);
FdEventHandlerPtr
do_stream_buf(int operation, int fd, int offset, char **buf_location, int len,
int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr),
void *data);
FdEventHandlerPtr
schedule_stream(int operation, int fd, int offset,
char *header, int hlen,
char *buf, int len, char *buf2, int len2, char *buf3, int len3,
char **buf_location,
int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr),
void *data);
int do_scheduled_stream(int, FdEventHandlerPtr);
int streamRequestDone(StreamRequestPtr);
FdEventHandlerPtr
do_connect(struct _Atom *addr, int index, int port,
int (*handler)(int, FdEventHandlerPtr, ConnectRequestPtr),
void *data);
int do_scheduled_connect(int, FdEventHandlerPtr event);
FdEventHandlerPtr
do_accept(int fd,
int (*handler)(int, FdEventHandlerPtr, AcceptRequestPtr),
void* data);
FdEventHandlerPtr
schedule_accept(int fd,
int (*handler)(int, FdEventHandlerPtr, AcceptRequestPtr),
void* data);
int do_scheduled_accept(int, FdEventHandlerPtr event);
FdEventHandlerPtr
create_listener(char *address, int port,
int (*handler)(int, FdEventHandlerPtr, AcceptRequestPtr),
void *data);
int setNonblocking(int fd, int nonblocking);
int setNodelay(int fd, int nodelay);
int setV6only(int fd, int v6only);
int lingeringClose(int fd);
typedef struct _NetAddress {
int prefix;
int af;
unsigned char data[16];
} NetAddressRec, *NetAddressPtr;
NetAddressPtr parseNetAddress(AtomListPtr list);
int netAddressMatch(int fd, NetAddressPtr list) ATTRIBUTE ((pure));