| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #define IO_READ 0 |
|---|
| 25 | #define IO_WRITE 1 |
|---|
| 26 | #define IO_MASK 0xFF |
|---|
| 27 | |
|---|
| 28 | #define IO_NOTNOW 0x100 |
|---|
| 29 | |
|---|
| 30 | #define IO_IMMEDIATE 0x200 |
|---|
| 31 | |
|---|
| 32 | #define IO_CHUNKED 0x400 |
|---|
| 33 | |
|---|
| 34 | #define IO_END 0x800 |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | #define IO_BUF3 0x1000 |
|---|
| 38 | |
|---|
| 39 | #define IO_BUF_LOCATION 0x2000 |
|---|
| 40 | |
|---|
| 41 | typedef 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 | |
|---|
| 66 | typedef 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 | |
|---|
| 77 | typedef struct _AcceptRequest { |
|---|
| 78 | int fd; |
|---|
| 79 | int (*handler)(int, FdEventHandlerPtr, struct _AcceptRequest*); |
|---|
| 80 | void *data; |
|---|
| 81 | } AcceptRequestRec, *AcceptRequestPtr; |
|---|
| 82 | |
|---|
| 83 | void preinitIo(); |
|---|
| 84 | void initIo(); |
|---|
| 85 | |
|---|
| 86 | FdEventHandlerPtr |
|---|
| 87 | do_stream(int operation, int fd, int offset, char *buf, int len, |
|---|
| 88 | int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), |
|---|
| 89 | void *data); |
|---|
| 90 | |
|---|
| 91 | FdEventHandlerPtr |
|---|
| 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), |
|---|
| 95 | void *data); |
|---|
| 96 | |
|---|
| 97 | FdEventHandlerPtr |
|---|
| 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), |
|---|
| 101 | void *data); |
|---|
| 102 | |
|---|
| 103 | FdEventHandlerPtr |
|---|
| 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), |
|---|
| 107 | void *data); |
|---|
| 108 | |
|---|
| 109 | FdEventHandlerPtr |
|---|
| 110 | do_stream_buf(int operation, int fd, int offset, char **buf_location, int len, |
|---|
| 111 | int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), |
|---|
| 112 | void *data); |
|---|
| 113 | |
|---|
| 114 | FdEventHandlerPtr |
|---|
| 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, |
|---|
| 118 | char **buf_location, |
|---|
| 119 | int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), |
|---|
| 120 | void *data); |
|---|
| 121 | |
|---|
| 122 | int do_scheduled_stream(int, FdEventHandlerPtr); |
|---|
| 123 | int streamRequestDone(StreamRequestPtr); |
|---|
| 124 | |
|---|
| 125 | FdEventHandlerPtr |
|---|
| 126 | do_connect(struct _Atom *addr, int index, int port, |
|---|
| 127 | int (*handler)(int, FdEventHandlerPtr, ConnectRequestPtr), |
|---|
| 128 | void *data); |
|---|
| 129 | |
|---|
| 130 | int do_scheduled_connect(int, FdEventHandlerPtr event); |
|---|
| 131 | |
|---|
| 132 | FdEventHandlerPtr |
|---|
| 133 | do_accept(int fd, |
|---|
| 134 | int (*handler)(int, FdEventHandlerPtr, AcceptRequestPtr), |
|---|
| 135 | void* data); |
|---|
| 136 | |
|---|
| 137 | FdEventHandlerPtr |
|---|
| 138 | schedule_accept(int fd, |
|---|
| 139 | int (*handler)(int, FdEventHandlerPtr, AcceptRequestPtr), |
|---|
| 140 | void* data); |
|---|
| 141 | |
|---|
| 142 | int do_scheduled_accept(int, FdEventHandlerPtr event); |
|---|
| 143 | |
|---|
| 144 | FdEventHandlerPtr |
|---|
| 145 | create_listener(char *address, int port, |
|---|
| 146 | int (*handler)(int, FdEventHandlerPtr, AcceptRequestPtr), |
|---|
| 147 | void *data); |
|---|
| 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); |
|---|
| 152 | |
|---|
| 153 | typedef struct _NetAddress { |
|---|
| 154 | int prefix; |
|---|
| 155 | int af; |
|---|
| 156 | unsigned char data[16]; |
|---|
| 157 | } NetAddressRec, *NetAddressPtr; |
|---|
| 158 | |
|---|
| 159 | NetAddressPtr parseNetAddress(AtomListPtr list); |
|---|
| 160 | int netAddressMatch(int fd, NetAddressPtr list) ATTRIBUTE ((pure)); |
|---|