src/server/util/io.h

changeset 385
a1f4cb076d2f
parent 361
570026d3a685
child 406
e5d96f6b9306
equal deleted inserted replaced
210:21274e5950af 385:a1f4cb076d2f
87 #elif defined(XP_WIN32) 87 #elif defined(XP_WIN32)
88 SOCKET fd; 88 SOCKET fd;
89 #endif 89 #endif
90 }; 90 };
91 91
92 #define HTTP_STREAM_CBUF_SIZE 16
92 struct HttpStream { 93 struct HttpStream {
93 IOStream st; 94 IOStream st;
94 IOStream *fd; 95 IOStream *fd;
96
97 /*
98 * content-length or current chunk size
99 */
95 uint64_t max_read; 100 uint64_t max_read;
101 /*
102 * total bytes read (with content-length) or bytes read of current chunk
103 */
96 uint64_t read; 104 uint64_t read;
105 /*
106 * total bytes read with chunked transfer encoding
107 */
108 uint64_t read_total;
109 /*
110 * read buffer (used only with chunked transfer encoding)
111 */
112 char *readbuf;
113 /*
114 * readbuf allocated size
115 */
116 size_t bufsize;
117 /*
118 * number of bytes currently stored in readbuf
119 */
120 int *buflen;
121 /*
122 * current position in the read buffer
123 */
124 int *bufpos;
125 /*
126 * current chunk_buf position
127 */
128 int chunk_buf_pos;
129 /*
130 * buffer used only for parsing chunk headers
131 */
132 char chunk_buf[HTTP_STREAM_CBUF_SIZE];
133 /*
134 * chunked transfer encoding for write enabled?
135 */
97 WSBool chunked_enc; 136 WSBool chunked_enc;
98 WSBool buffered; 137 /*
138 * end of file indicator (read)
139 */
140 WSBool read_eof;
141 /*
142 * end of file indicator (write)
143 */
144 WSBool write_eof;
99 }; 145 };
100 146
101 typedef struct SSLStream { 147 typedef struct SSLStream {
102 IOStream st; 148 IOStream st;
103 SSL *ssl; 149 SSL *ssl;
118 int net_sys_poll(SysStream *st, EventHandler *ev, int events, Event *cb); 164 int net_sys_poll(SysStream *st, EventHandler *ev, int events, Event *cb);
119 165
120 /* http stream */ 166 /* http stream */
121 IOStream* httpstream_new(pool_handle_t *pool, IOStream *fd); 167 IOStream* httpstream_new(pool_handle_t *pool, IOStream *fd);
122 168
169 int httpstream_enable_chunked_read(IOStream *st, char *buffer, size_t bufsize, int *cursize, int *pos);
170 int httpstream_enable_chunked_write(IOStream *st);
171 int httpstream_set_max_read(IOStream *st, int64_t maxread);
172 WSBool httpstream_eof(IOStream *st);
173
123 ssize_t net_http_write(HttpStream *st, void *buf, size_t nbytes); 174 ssize_t net_http_write(HttpStream *st, void *buf, size_t nbytes);
124 ssize_t net_http_writev(HttpStream *st, struct iovec *iovec, int iovcnt); 175 ssize_t net_http_writev(HttpStream *st, struct iovec *iovec, int iovcnt);
125 ssize_t net_http_read(HttpStream *st, void *buf, size_t nbytes); 176 ssize_t net_http_read(HttpStream *st, void *buf, size_t nbytes);
177 ssize_t net_http_read_chunked(HttpStream *st, void *buf, size_t nbytes);
126 ssize_t net_http_sendfile(HttpStream *st, sendfiledata *sfd); 178 ssize_t net_http_sendfile(HttpStream *st, sendfiledata *sfd);
127 void net_http_close(HttpStream *st); 179 void net_http_close(HttpStream *st);
128 void net_http_finish(HttpStream *st); 180 void net_http_finish(HttpStream *st);
129 void net_http_setmode(HttpStream *st, int mode); 181 void net_http_setmode(HttpStream *st, int mode);
130 int net_http_poll(HttpStream *st, EventHandler *ev, int events, Event *cb); 182 int net_http_poll(HttpStream *st, EventHandler *ev, int events, Event *cb);

mercurial