io.h 5.0 KB

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