| 75 (io_sendfile_f)NET_SYS_SENDFILE, |
75 (io_sendfile_f)NET_SYS_SENDFILE, |
| 76 (io_close_f)net_sys_close, |
76 (io_close_f)net_sys_close, |
| 77 NULL, |
77 NULL, |
| 78 (io_setmode_f)net_sys_setmode, |
78 (io_setmode_f)net_sys_setmode, |
| 79 (io_poll_f)net_sys_poll, |
79 (io_poll_f)net_sys_poll, |
| |
80 (io_free_f)sysstream_free, |
| 80 0, |
81 0, |
| 81 0 |
82 0 |
| 82 }; |
83 }; |
| 83 |
84 |
| 84 IOStream http_io_funcs = { |
85 IOStream http_io_funcs = { |
| 88 (io_sendfile_f)net_http_sendfile, |
89 (io_sendfile_f)net_http_sendfile, |
| 89 (io_close_f)net_http_close, |
90 (io_close_f)net_http_close, |
| 90 (io_finish_f)net_http_finish, |
91 (io_finish_f)net_http_finish, |
| 91 (io_setmode_f)net_http_setmode, |
92 (io_setmode_f)net_http_setmode, |
| 92 (io_poll_f)net_http_poll, |
93 (io_poll_f)net_http_poll, |
| |
94 (io_free_f)httpstream_free, |
| 93 0, |
95 0, |
| 94 IO_STREAM_TYPE_HTTP |
96 IO_STREAM_TYPE_HTTP |
| 95 }; |
97 }; |
| 96 |
98 |
| 97 IOStream ssl_io_funcs = { |
99 IOStream ssl_io_funcs = { |
| 101 NULL, |
103 NULL, |
| 102 (io_close_f)net_ssl_close, |
104 (io_close_f)net_ssl_close, |
| 103 (io_finish_f)net_ssl_finish, |
105 (io_finish_f)net_ssl_finish, |
| 104 (io_setmode_f)net_ssl_setmode, |
106 (io_setmode_f)net_ssl_setmode, |
| 105 (io_poll_f)net_ssl_poll, |
107 (io_poll_f)net_ssl_poll, |
| |
108 (io_free_f)sslstream_free, |
| 106 0, |
109 0, |
| 107 IO_STREAM_TYPE_SSL |
110 IO_STREAM_TYPE_SSL |
| 108 }; |
111 }; |
| 109 |
112 |
| 110 static int net_write_max_attempts = 16384; |
113 static int net_write_max_attempts = 16384; |
| 118 */ |
121 */ |
| 119 |
122 |
| 120 IOStream* Sysstream_new(pool_handle_t *pool, SYS_SOCKET fd) { |
123 IOStream* Sysstream_new(pool_handle_t *pool, SYS_SOCKET fd) { |
| 121 Sysstream *st = pool_malloc(pool, sizeof(Sysstream)); |
124 Sysstream *st = pool_malloc(pool, sizeof(Sysstream)); |
| 122 st->st = native_io_funcs; |
125 st->st = native_io_funcs; |
| |
126 st->pool = pool; |
| 123 st->fd = fd; |
127 st->fd = fd; |
| 124 return (IOStream*)st; |
128 return (IOStream*)st; |
| |
129 } |
| |
130 |
| |
131 void sysstream_free(IOStream *st) { |
| |
132 Sysstream *sys = (Sysstream*)st; |
| |
133 pool_free(sys->pool, st); |
| 125 } |
134 } |
| 126 |
135 |
| 127 #ifdef XP_UNIX |
136 #ifdef XP_UNIX |
| 128 ssize_t net_sys_write(Sysstream *st, const void *buf, size_t nbytes) { |
137 ssize_t net_sys_write(Sysstream *st, const void *buf, size_t nbytes) { |
| 129 ssize_t r = write(st->fd, buf, nbytes); |
138 ssize_t r = write(st->fd, buf, nbytes); |
| 284 st->write_chunk_buf_pos = 0; |
293 st->write_chunk_buf_pos = 0; |
| 285 st->chunked_enc = WS_FALSE; |
294 st->chunked_enc = WS_FALSE; |
| 286 st->read_eof = WS_TRUE; |
295 st->read_eof = WS_TRUE; |
| 287 st->write_eof = WS_FALSE; |
296 st->write_eof = WS_FALSE; |
| 288 return (IOStream*)st; |
297 return (IOStream*)st; |
| |
298 } |
| |
299 |
| |
300 void httpstream_free(IOStream *st) { |
| |
301 HttpStream *http = (HttpStream*)st; |
| |
302 http->fd->free(http->fd); |
| |
303 pool_free(http->pool, st); |
| 289 } |
304 } |
| 290 |
305 |
| 291 int httpstream_enable_chunked_read(IOStream *st, char *buffer, size_t bufsize, int *cursize, int *pos) { |
306 int httpstream_enable_chunked_read(IOStream *st, char *buffer, size_t bufsize, int *cursize, int *pos) { |
| 292 if(st->read != (io_read_f)net_http_read) { |
307 if(st->read != (io_read_f)net_http_read) { |
| 293 log_ereport(LOG_FAILURE, "%s", "httpstream_enable_chunked_read: IOStream is not an HttpStream"); |
308 log_ereport(LOG_FAILURE, "%s", "httpstream_enable_chunked_read: IOStream is not an HttpStream"); |
| 810 st->ssl = ssl; |
825 st->ssl = ssl; |
| 811 st->error = 0; |
826 st->error = 0; |
| 812 return (IOStream*)st; |
827 return (IOStream*)st; |
| 813 } |
828 } |
| 814 |
829 |
| |
830 void sslstream_free(IOStream *st) { |
| |
831 SSLStream *ssl = (SSLStream*)st; |
| |
832 SSL_free(ssl->ssl); |
| |
833 pool_free(ssl->pool, st); |
| |
834 } |
| |
835 |
| 815 ssize_t net_ssl_write(SSLStream *st, const void *buf, size_t nbytes) { |
836 ssize_t net_ssl_write(SSLStream *st, const void *buf, size_t nbytes) { |
| 816 int ret = SSL_write(st->ssl, buf, nbytes); |
837 int ret = SSL_write(st->ssl, buf, nbytes); |
| 817 if(ret <= 0) { |
838 if(ret <= 0) { |
| 818 st->error = SSL_get_error(st->ssl, ret); |
839 st->error = SSL_get_error(st->ssl, ret); |
| 819 if(st->error == SSL_ERROR_WANT_WRITE || st->error == SSL_ERROR_WANT_READ) { |
840 if(st->error == SSL_ERROR_WANT_WRITE || st->error == SSL_ERROR_WANT_READ) { |