1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #ifndef IOSTREAM_H
30 #define IOSTREAM_H
31
32 #include <openssl/ssl.h>
33 #include "../public/nsapi.h"
34 #include "systems.h"
35
36 #ifdef _WIN32
37 #include <windows.h>
38 #include <winsock2.h>
39 #endif
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 #ifdef XP_UNIX
46 #define SYS_SOCKET int
47 #elif defined(
XP_WIN32)
48 #define SYS_SOCKET SOCKET
49 #endif
50
51 #define IO_MODE_BLOCKING 0
52 #define IO_MODE_NONBLOCKING 1
53
54 #define IO_POLL_NONE 0
55 #define IO_POLL_IN 1
56 #define IO_POLL_OUT 2
57
58 typedef struct IOStream IOStream;
59 typedef struct SysStream SysStream;
60 typedef struct HttpStream HttpStream;
61
62 typedef ssize_t(*io_write_f)(IOStream *,
void *,
size_t);
63 typedef ssize_t(*io_writev_f)(IOStream *,
struct iovec *,
int);
64 typedef ssize_t(*io_read_f)(IOStream *,
void *,
size_t);
65 typedef ssize_t(*io_sendfile_f)(IOStream *, sendfiledata *);
66 typedef void(*io_close_f)(IOStream *);
67 typedef void(*io_finish_f)(IOStream *);
68 typedef void(*io_setmode_f)(IOStream *,
int);
69 typedef int(*io_poll_f)(IOStream *, EventHandler *,
int, Event *);
70
71 struct IOStream {
72 io_write_f write;
73 io_writev_f writev;
74 io_read_f read;
75 io_sendfile_f sendfile;
76 io_close_f close;
77 io_finish_f finish;
78 io_setmode_f setmode;
79 io_poll_f poll;
80 int io_errno;
81 };
82
83 struct SysStream {
84 IOStream st;
85 #ifdef XP_UNIX
86 int fd;
87 #elif defined(
XP_WIN32)
88 SOCKET fd;
89 #endif
90 };
91
92 struct HttpStream {
93 IOStream st;
94 IOStream *fd;
95 uint64_t max_read;
96 uint64_t read;
97 WSBool chunked_enc;
98 WSBool buffered;
99 };
100
101 typedef struct SSLStream {
102 IOStream st;
103 SSL *ssl;
104 int error;
105 } SSLStream;
106
107
108
109
110 IOStream* sysstream_new(
pool_handle_t *pool,
SYS_SOCKET fd);
111
112 ssize_t net_sys_write(SysStream *st,
void *buf,
size_t nbytes);
113 ssize_t net_sys_writev(SysStream *st,
struct iovec *iovec,
int iovcnt);
114 ssize_t net_sys_read(SysStream *st,
void *buf,
size_t nbytes);
115 ssize_t net_sys_sendfile(SysStream *st, sendfiledata *sfd);
116 void net_sys_close(SysStream *st);
117 void net_sys_setmode(SysStream *st,
int mode);
118 int net_sys_poll(SysStream *st, EventHandler *ev,
int events, Event *cb);
119
120
121 IOStream* httpstream_new(
pool_handle_t *pool, IOStream *fd);
122
123 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);
125 ssize_t net_http_read(HttpStream *st,
void *buf,
size_t nbytes);
126 ssize_t net_http_sendfile(HttpStream *st, sendfiledata *sfd);
127 void net_http_close(HttpStream *st);
128 void net_http_finish(HttpStream *st);
129 void net_http_setmode(HttpStream *st,
int mode);
130 int net_http_poll(HttpStream *st, EventHandler *ev,
int events, Event *cb);
131
132
133 IOStream* sslstream_new(
pool_handle_t *pool,
SSL *ssl);
134
135 ssize_t net_ssl_write(SSLStream *st,
void *buf,
size_t nbytes);
136 ssize_t net_ssl_writev(SSLStream *st,
struct iovec *iovec,
int iovcnt);
137 ssize_t net_ssl_read(SSLStream *st,
void *buf,
size_t nbytes);
138 void net_ssl_close(SSLStream *st);
139 void net_ssl_finish(SSLStream *st);
140 void net_ssl_setmode(SSLStream *st,
int mode);
141 int net_ssl_poll(SSLStream *st, EventHandler *ev,
int events, Event *cb);
142
143
144 ssize_t net_fallback_sendfile(IOStream *fd, sendfiledata *sfd);
145 void net_finish(
SYS_NETFD fd);
146
147 #ifdef __cplusplus
148 }
149 #endif
150
151 #endif
152
153