root / trunk / src / dot / proxy / io.h

Revision 7618, 5.0 kB (checked in by BradNeuberg, 22 months ago)

Local and remote SVN repositories somehow became out of sync and corrupted -- re-adding these in

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