2 Copyright (c) 2003-2006 by Juliusz Chroboczek
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 /* request->operation */
27 /* Do not initiate operation now -- wait for the poll loop. */
28 #define IO_NOTNOW 0x100
29 /* Call the progress handler once if no data arrives immediately. */
30 #define IO_IMMEDIATE 0x200
31 /* Emit a chunk length before every write operation */
32 #define IO_CHUNKED 0x400
33 /* Emit a zero-length chunk at the end if chunked */
36 /* Internal -- header is really buf3 */
37 #define IO_BUF3 0x1000
38 /* Internal -- header is really buf_location */
39 #define IO_BUF_LOCATION 0x2000
41 typedef struct _StreamRequest
{
62 int (*handler
)(int, FdEventHandlerPtr
, struct _StreamRequest
*);
64 } StreamRequestRec
, *StreamRequestPtr
;
66 typedef struct _ConnectRequest
{
73 int (*handler
)(int, FdEventHandlerPtr
, struct _ConnectRequest
*);
75 } ConnectRequestRec
, *ConnectRequestPtr
;
77 typedef struct _AcceptRequest
{
79 int (*handler
)(int, FdEventHandlerPtr
, struct _AcceptRequest
*);
81 } AcceptRequestRec
, *AcceptRequestPtr
;
87 do_stream(int operation
, int fd
, int offset
, char *buf
, int len
,
88 int (*handler
)(int, FdEventHandlerPtr
, StreamRequestPtr
),
92 do_stream_h(int operation
, int fd
, int offset
,
93 char *header
, int hlen
, char *buf
, int len
,
94 int (*handler
)(int, FdEventHandlerPtr
, StreamRequestPtr
),
98 do_stream_2(int operation
, int fd
, int offset
,
99 char *buf
, int len
, char *buf2
, int len2
,
100 int (*handler
)(int, FdEventHandlerPtr
, StreamRequestPtr
),
104 do_stream_3(int operation
, int fd
, int offset
,
105 char *buf
, int len
, char *buf2
, int len2
, char *buf3
, int len3
,
106 int (*handler
)(int, FdEventHandlerPtr
, StreamRequestPtr
),
110 do_stream_buf(int operation
, int fd
, int offset
, char **buf_location
, int len
,
111 int (*handler
)(int, FdEventHandlerPtr
, StreamRequestPtr
),
115 schedule_stream(int operation
, int fd
, int offset
,
116 char *header
, int hlen
,
117 char *buf
, int len
, char *buf2
, int len2
, char *buf3
, int len3
,
119 int (*handler
)(int, FdEventHandlerPtr
, StreamRequestPtr
),
122 int do_scheduled_stream(int, FdEventHandlerPtr
);
123 int streamRequestDone(StreamRequestPtr
);
126 do_connect(struct _Atom
*addr
, int index
, int port
,
127 int (*handler
)(int, FdEventHandlerPtr
, ConnectRequestPtr
),
130 int do_scheduled_connect(int, FdEventHandlerPtr event
);
134 int (*handler
)(int, FdEventHandlerPtr
, AcceptRequestPtr
),
138 schedule_accept(int fd
,
139 int (*handler
)(int, FdEventHandlerPtr
, AcceptRequestPtr
),
142 int do_scheduled_accept(int, FdEventHandlerPtr event
);
145 create_listener(char *address
, int port
,
146 int (*handler
)(int, FdEventHandlerPtr
, AcceptRequestPtr
),
148 int setNonblocking(int fd
, int nonblocking
);
149 int setNodelay(int fd
, int nodelay
);
150 int setV6only(int fd
, int v6only
);
151 int lingeringClose(int fd
);
153 typedef struct _NetAddress
{
156 unsigned char data
[16];
157 } NetAddressRec
, *NetAddressPtr
;
159 NetAddressPtr
parseNetAddress(AtomListPtr list
);
160 int netAddressMatch(int fd
, NetAddressPtr list
) ATTRIBUTE ((pure
));