Mon, 02 May 2022 20:20:37 +0200
send response in webdav_delete
1 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
44
3da1f7b6847f
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
1 | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
29 | #ifdef __gnu_linux__ |
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
30 | #define _GNU_SOURCE |
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
31 | #endif |
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
32 | |
1 | 33 | #include <unistd.h> |
34 | #include <stdlib.h> | |
147
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
35 | |
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
36 | #ifdef XP_UNIX |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
37 | #include <sys/uio.h> |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
38 | #include <sys/uio.h> |
147
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
39 | #endif |
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
40 | |
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
41 | #ifdef XP_WIN32 |
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
42 | |
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
43 | #endif |
111
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
44 | |
126
631aaa01b2b5
fixes chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
112
diff
changeset
|
45 | #if defined(LINUX) || defined(SOLARIS) |
54 | 46 | #include <sys/sendfile.h> |
126
631aaa01b2b5
fixes chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
112
diff
changeset
|
47 | #define WS_SENDFILE |
631aaa01b2b5
fixes chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
112
diff
changeset
|
48 | #elif defined(BSD) |
111
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
49 | #if defined(__NetBSD__) || defined(__OpenBSD__) |
112 | 50 | #define net_sys_sendfile net_fallback_sendfile |
126
631aaa01b2b5
fixes chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
112
diff
changeset
|
51 | #else |
631aaa01b2b5
fixes chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
112
diff
changeset
|
52 | #define WS_SENDFILE |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
53 | #endif |
147
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
54 | #endif |
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
55 | |
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
56 | #ifdef WS_SENDFILE |
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
57 | #define NET_SYS_SENDFILE net_sys_sendfile |
126
631aaa01b2b5
fixes chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
112
diff
changeset
|
58 | #else |
147
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
59 | #define NET_SYS_SENDFILE net_fallback_sendfile |
111
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
60 | #endif |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
61 | |
147
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
62 | |
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
63 | |
54 | 64 | #include "../daemon/vfs.h" |
1 | 65 | #include "io.h" |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
66 | #include "pool.h" |
171
af7e2d80dee6
adds wrapper for close syscall with error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
67 | #include "../daemon/netsite.h" |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
68 | #include "../daemon/event.h" |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
69 | #include "ucx/utils.h" |
1 | 70 | |
71 | IOStream native_io_funcs = { | |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
72 | (io_write_f)net_sys_write, |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
73 | (io_writev_f)net_sys_writev, |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
74 | (io_read_f)net_sys_read, |
147
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
75 | (io_sendfile_f)NET_SYS_SENDFILE, |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
76 | (io_close_f)net_sys_close, |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
77 | NULL, |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
78 | (io_setmode_f)net_sys_setmode, |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
79 | (io_poll_f)net_sys_poll, |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
80 | 0 |
1 | 81 | }; |
82 | ||
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
83 | IOStream http_io_funcs = { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
84 | (io_write_f)net_http_write, |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
85 | (io_writev_f)net_http_writev, |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
86 | (io_read_f)net_http_read, |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
87 | (io_sendfile_f)net_http_sendfile, |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
88 | (io_close_f)net_http_close, |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
89 | (io_finish_f)net_http_finish, |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
90 | (io_setmode_f)net_http_setmode, |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
91 | (io_poll_f)net_http_poll, |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
92 | 0 |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
93 | }; |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
94 | |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
95 | IOStream ssl_io_funcs = { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
96 | (io_write_f)net_ssl_write, |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
97 | (io_writev_f)net_ssl_writev, |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
98 | (io_read_f)net_ssl_read, |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
99 | NULL, |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
100 | (io_close_f)net_ssl_close, |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
101 | (io_finish_f)net_ssl_finish, |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
102 | (io_setmode_f)net_ssl_setmode, |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
103 | (io_poll_f)net_ssl_poll, |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
104 | 0 |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
105 | }; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
106 | |
1 | 107 | |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
108 | /* |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
109 | * SysStream implementation |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
110 | */ |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
111 | |
147
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
112 | IOStream* sysstream_new(pool_handle_t *pool, SYS_SOCKET fd) { |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
113 | SysStream *st = pool_malloc(pool, sizeof(SysStream)); |
1 | 114 | st->st = native_io_funcs; |
115 | st->fd = fd; | |
116 | return (IOStream*)st; | |
117 | } | |
118 | ||
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
119 | #ifdef XP_UNIX |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
120 | ssize_t net_sys_write(SysStream *st, void *buf, size_t nbytes) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
121 | return write(st->fd, buf, nbytes); |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
122 | } |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
123 | |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
124 | ssize_t net_sys_writev(SysStream *st, struct iovec *iovec, int iovcnt) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
125 | return writev(st->fd, iovec, iovcnt); |
64
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
126 | } |
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
127 | |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
128 | ssize_t net_sys_read(SysStream *st, void *buf, size_t nbytes) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
129 | return read(st->fd, buf, nbytes); |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
130 | } |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
131 | |
126
631aaa01b2b5
fixes chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
112
diff
changeset
|
132 | #ifdef WS_SENDFILE |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
133 | ssize_t net_sys_sendfile(SysStream *st, sendfiledata *sfd) { |
54 | 134 | ssize_t ret = 0; |
135 | off_t fileoffset = sfd->offset; | |
136 | if(sfd->fd->fd != -1) { | |
71 | 137 | #ifdef BSD |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
138 | struct iovec hdvec; |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
139 | hdvec.iov_base = (void*)sfd->header; |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
140 | hdvec.iov_len = sfd->hlen; |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
141 | struct iovec trvec; |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
142 | trvec.iov_base = (void*)sfd->trailer; |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
143 | trvec.iov_len = sfd->tlen; |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
144 | struct sf_hdtr hdtr; |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
145 | hdtr.headers = &hdvec; |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
146 | hdtr.hdr_cnt = 1; |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
147 | hdtr.trailers = &trvec; |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
148 | hdtr.trl_cnt = 1; |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
149 | |
70
4e6e812c1d97
fixed some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
150 | off_t len = sfd->len; |
71 | 151 | #ifdef OSX |
152 | ret = sendfile(sfd->fd->fd, st->fd, fileoffset, &len, &hdtr, 0); | |
153 | #else // BSD | |
154 | ret = sendfile( | |
155 | sfd->fd->fd, | |
156 | st->fd, | |
157 | fileoffset, | |
158 | sfd->len, | |
159 | &hdtr, | |
160 | NULL, | |
161 | 0); | |
162 | #endif | |
163 | #else // Solaris/Linux | |
104
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
164 | if(sfd->header) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
165 | ret += write(st->fd, sfd->header, sfd->hlen); |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
166 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
167 | ret += sendfile(st->fd, sfd->fd->fd, &fileoffset, sfd->len); |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
168 | if(sfd->trailer) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
169 | ret += write(st->fd, sfd->trailer, sfd->tlen); |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
170 | } |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
171 | #endif |
54 | 172 | } else { |
126
631aaa01b2b5
fixes chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
112
diff
changeset
|
173 | return net_fallback_sendfile((IOStream*)st, sfd); |
54 | 174 | } |
175 | ||
176 | return ret; | |
177 | } | |
111
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
178 | #endif |
54 | 179 | |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
180 | void net_sys_close(SysStream *st) { |
171
af7e2d80dee6
adds wrapper for close syscall with error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
181 | system_close(st->fd); |
80
0de4a90979e1
fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
182 | } |
0de4a90979e1
fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
183 | |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
184 | void net_sys_setmode(SysStream *st, int mode) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
185 | int flags; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
186 | if (-1 == (flags = fcntl(st->fd, F_GETFL, 0))) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
187 | flags = 0; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
188 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
189 | if(mode == IO_MODE_BLOCKING) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
190 | if (fcntl(st->fd, F_SETFL, flags & ~O_NONBLOCK) != 0) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
191 | perror("fcntl"); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
192 | // TODO: error |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
193 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
194 | } else if(mode == IO_MODE_NONBLOCKING) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
195 | if (fcntl(st->fd, F_SETFL, flags | O_NONBLOCK) != 0) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
196 | perror("fcntl"); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
197 | // TODO: error |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
198 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
199 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
200 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
201 | |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
202 | int net_sys_poll(SysStream *st, EventHandler *ev, int events, Event *cb) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
203 | switch(events) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
204 | default: return -1; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
205 | case IO_POLL_NONE: return ev_remove_poll(ev, st->fd); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
206 | case IO_POLL_IN: return ev_pollin(ev, st->fd, cb); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
207 | case IO_POLL_OUT: return ev_pollout(ev, st->fd, cb); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
208 | case IO_POLL_IN | IO_POLL_OUT: return -1; // TODO: implement |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
209 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
210 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
211 | |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
212 | #elif defined(XP_WIN32) |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
213 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
214 | ssize_t net_sys_write(SysStream *st, void *buf, size_t nbytes) { |
147
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
215 | int ret = send(st->fd, buf, nbytes, 0); |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
216 | if(ret == SOCKET_ERROR) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
217 | return IO_ERROR; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
218 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
219 | return ret; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
220 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
221 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
222 | ssize_t net_sys_writev(SysStream *st, struct iovec *iovec, int iovcnt) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
223 | // TODO |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
224 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
225 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
226 | ssize_t net_sys_read(SysStream *st, void *buf, size_t nbytes) { |
147
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
227 | int ret = recv(st->fd, buf, nbytes, 0); |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
228 | if(ret == SOCKET_ERROR) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
229 | return IO_ERROR; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
230 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
231 | return ret; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
232 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
233 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
234 | ssize_t net_sys_sendfile(SysStream *st, sendfiledata *sfd) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
235 | // TODO |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
236 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
237 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
238 | void net_sys_close(SysStream *st) { |
147
d050449c3b9e
ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
239 | closesocket(st->fd); |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
240 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
241 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
242 | #endif |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
243 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
244 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
245 | /* |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
246 | * HttpStream implementation |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
247 | */ |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
248 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
249 | IOStream* httpstream_new(pool_handle_t *pool, IOStream *fd) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
250 | HttpStream *st = pool_malloc(pool, sizeof(HttpStream)); |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
251 | st->st = http_io_funcs; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
252 | st->fd = fd; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
253 | st->max_read = 0; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
254 | st->read = 0; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
255 | st->chunked_enc = WS_FALSE; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
256 | st->buffered = WS_FALSE; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
257 | return (IOStream*)st; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
258 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
259 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
260 | ssize_t net_http_write(HttpStream *st, void *buf, size_t nbytes) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
261 | IOStream *fd = st->fd; |
80
0de4a90979e1
fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
262 | if(st->chunked_enc) { |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
263 | // TODO: on some plattforms iov_len is smaller than size_t |
126
631aaa01b2b5
fixes chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
112
diff
changeset
|
264 | struct iovec io[3]; |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
265 | char chunk_len[16]; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
266 | io[0].iov_base = chunk_len; |
126
631aaa01b2b5
fixes chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
112
diff
changeset
|
267 | io[0].iov_len = snprintf(chunk_len, 16, "%zx\r\n", nbytes); |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
268 | io[1].iov_base = buf; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
269 | io[1].iov_len = nbytes; |
126
631aaa01b2b5
fixes chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
112
diff
changeset
|
270 | io[2].iov_base = "\r\n"; |
631aaa01b2b5
fixes chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
112
diff
changeset
|
271 | io[2].iov_len = 2; |
235
4990147c58d0
add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
272 | // TODO: FIXME: if r < sum of iov_len, everything would explode |
4990147c58d0
add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
273 | // we need to store the chunk state and remaining bytes |
126
631aaa01b2b5
fixes chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
112
diff
changeset
|
274 | ssize_t r = fd->writev(fd, io, 3); |
235
4990147c58d0
add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
275 | return r - io[0].iov_len - io[2].iov_len; |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
276 | } else { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
277 | return fd->write(fd, buf, nbytes); |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
278 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
279 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
280 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
281 | ssize_t net_http_writev(HttpStream *st, struct iovec *iovec, int iovcnt) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
282 | IOStream *fd = st->fd; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
283 | if(st->chunked_enc) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
284 | struct iovec *io = calloc(iovcnt + 1, sizeof(struct iovec)); |
251
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
235
diff
changeset
|
285 | if(!io) { |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
235
diff
changeset
|
286 | return 0; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
235
diff
changeset
|
287 | } |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
288 | char chunk_len[16]; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
289 | io[0].iov_base = chunk_len; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
290 | size_t len = 0; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
291 | for(int i=0;i<iovcnt;i++) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
292 | len += iovec[i].iov_len; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
293 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
294 | io[0].iov_len = snprintf(chunk_len, 16, "\r\n%zx\r\n", len); |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
295 | memcpy(io + 1, iovec, iovcnt * sizeof(struct iovec)); |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
296 | ssize_t r = fd->writev(fd, io, iovcnt + 1); |
251
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
235
diff
changeset
|
297 | |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
235
diff
changeset
|
298 | ssize_t ret = r - io[0].iov_len; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
235
diff
changeset
|
299 | free(io); |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
235
diff
changeset
|
300 | return ret; |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
301 | } else { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
302 | return fd->writev(fd, iovec, iovcnt); |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
303 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
304 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
305 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
306 | ssize_t net_http_read(HttpStream *st, void *buf, size_t nbytes) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
307 | if(st->max_read != 0 && st->read >= st->max_read) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
308 | return 0; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
309 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
310 | ssize_t r = st->fd->read(st->fd, buf, nbytes); |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
311 | st->read += r; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
312 | return r; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
313 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
314 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
315 | ssize_t net_http_sendfile(HttpStream *st, sendfiledata *sfd) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
316 | ssize_t ret = 0; |
112 | 317 | // TODO: support chunked transfer encoding |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
318 | if(st->fd->sendfile) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
319 | ret = st->fd->sendfile(st->fd, sfd); |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
320 | } else { |
112 | 321 | ret = net_fallback_sendfile((IOStream*)st, sfd); |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
322 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
323 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
324 | return ret; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
325 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
326 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
327 | void net_http_close(HttpStream *st) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
328 | st->fd->close(st->fd); |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
329 | } |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
330 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
331 | void net_http_finish(HttpStream *st) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
332 | if(st->chunked_enc) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
333 | st->fd->write(st->fd, "0\r\n\r\n", 5); |
80
0de4a90979e1
fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
334 | } |
0de4a90979e1
fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
335 | } |
0de4a90979e1
fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
336 | |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
337 | void net_http_setmode(HttpStream *st, int mode) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
338 | st->fd->setmode(st->fd, mode); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
339 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
340 | |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
341 | int net_http_poll(HttpStream *st, EventHandler *ev, int events, Event *cb) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
342 | return st->fd->poll(st->fd, ev, events, cb); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
343 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
344 | |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
345 | |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
346 | /* |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
347 | * SSLStream implementation |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
348 | */ |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
349 | |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
350 | IOStream* sslstream_new(pool_handle_t *pool, SSL *ssl) { |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
351 | SSLStream *st = pool_malloc(pool, sizeof(SSLStream)); |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
352 | st->st = ssl_io_funcs; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
353 | st->ssl = ssl; |
133
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
354 | st->error = 0; |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
355 | return (IOStream*)st; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
356 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
357 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
358 | ssize_t net_ssl_write(SSLStream *st, void *buf, size_t nbytes) { |
133
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
359 | int ret = SSL_write(st->ssl, buf, nbytes); |
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
360 | if(ret <= 0) { |
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
361 | st->error = SSL_get_error(st->ssl, ret); |
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
362 | } |
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
363 | return ret; |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
364 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
365 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
366 | ssize_t net_ssl_writev(SSLStream *st, struct iovec *iovec, int iovcnt) { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
367 | ssize_t r = 0; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
368 | for(int i=0;i<iovcnt;i++) { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
369 | int ret = SSL_write(st->ssl, iovec[i].iov_base, iovec[i].iov_len); |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
370 | if(ret <= 0) { |
133
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
371 | st->error = SSL_get_error(st->ssl, ret); |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
372 | return 0; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
373 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
374 | r += ret; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
375 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
376 | return r; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
377 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
378 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
379 | ssize_t net_ssl_read(SSLStream *st, void *buf, size_t nbytes) { |
133
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
380 | int ret = SSL_read(st->ssl, buf, nbytes); |
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
381 | if(ret <= 0) { |
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
382 | st->error = SSL_get_error(st->ssl, ret); |
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
383 | } |
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
384 | return ret; |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
385 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
386 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
387 | void net_ssl_close(SSLStream *st) { |
133
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
388 | int ret = SSL_shutdown(st->ssl); |
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
389 | if(ret != 1) { |
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
390 | st->error = SSL_get_error(st->ssl, ret); |
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
126
diff
changeset
|
391 | } |
171
af7e2d80dee6
adds wrapper for close syscall with error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
392 | system_close(SSL_get_fd(st->ssl)); |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
393 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
394 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
395 | void net_ssl_finish(SSLStream *st) { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
396 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
397 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
398 | |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
399 | void net_ssl_setmode(SSLStream *st, int mode) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
400 | int flags; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
401 | if (-1 == (flags = fcntl(SSL_get_fd(st->ssl), F_GETFL, 0))) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
402 | flags = 0; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
403 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
404 | if(mode == IO_MODE_BLOCKING) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
405 | if (fcntl(SSL_get_fd(st->ssl), F_SETFL, flags & ~O_NONBLOCK) != 0) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
406 | perror("fcntl"); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
407 | // TODO: error |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
408 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
409 | } else if(mode == IO_MODE_NONBLOCKING) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
410 | if (fcntl(SSL_get_fd(st->ssl), F_SETFL, flags | O_NONBLOCK) != 0) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
411 | perror("fcntl"); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
412 | // TODO: error |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
413 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
414 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
415 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
416 | |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
417 | int net_ssl_poll(SSLStream *st, EventHandler *ev, int events, Event *cb) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
418 | int fd = SSL_get_fd(st->ssl); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
419 | switch(events) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
420 | default: return -1; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
421 | case IO_POLL_NONE: return ev_remove_poll(ev, fd); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
422 | case IO_POLL_IN: return ev_pollin(ev, fd, cb); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
423 | case IO_POLL_OUT: return ev_pollout(ev, fd, cb); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
424 | case IO_POLL_IN | IO_POLL_OUT: return -1; // TODO: implement |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
425 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
426 | } |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
427 | |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
428 | /* -------------------- public nsapi network functions -------------------- */ |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
429 | |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
430 | ssize_t net_read(SYS_NETFD fd, void *buf, size_t nbytes) { |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
431 | ssize_t r = ((IOStream*)fd)->read(fd, buf, nbytes); |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
432 | if(r == 0) { |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
433 | return IO_EOF; |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
434 | } else if(r < 0) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
435 | ((IOStream*)fd)->io_errno = errno; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
436 | return IO_ERROR; |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
437 | } |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
438 | return r; |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
439 | } |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
440 | |
9
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
441 | ssize_t net_write(SYS_NETFD fd, void *buf, size_t nbytes) { |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
442 | ssize_t r = ((IOStream*)fd)->write(fd, buf, nbytes); |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
443 | if(r < 0) { |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
444 | ((IOStream*)fd)->io_errno = errno; |
9
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
445 | return IO_ERROR; |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
446 | } |
9
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
447 | return r; |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
448 | } |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
449 | |
64
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
450 | ssize_t net_writev(SYS_NETFD fd, struct iovec *iovec, int iovcnt) { |
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
451 | ssize_t r = ((IOStream*)fd)->writev(fd, iovec, iovcnt); |
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
452 | if(r < 0) { |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
453 | ((IOStream*)fd)->io_errno = errno; |
64
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
454 | return IO_ERROR; |
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
455 | } |
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
456 | return r; |
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
457 | } |
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
458 | |
23
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
459 | ssize_t net_printf(SYS_NETFD fd, char *format, ...) { |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
460 | va_list arg; |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
461 | va_start(arg, format); |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
462 | sstr_t buf = ucx_vasprintf(ucx_default_allocator(), format, arg); |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
463 | ssize_t r = net_write(fd, buf.ptr, buf.length); |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
464 | free(buf.ptr); |
142
55298bc9ed28
adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
465 | va_end(arg); |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
466 | if(r < 0) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
467 | ((IOStream*)fd)->io_errno = errno; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
468 | } |
64
c7f5b062e622
added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
469 | return r; |
23
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
470 | } |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
471 | |
54 | 472 | ssize_t net_sendfile(SYS_NETFD fd, sendfiledata *sfd) { |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
473 | IOStream *out = fd; |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
474 | if(out->sendfile && sfd->fd && sfd->fd->fd != -1) { |
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
475 | ssize_t r = out->sendfile(fd, sfd); |
54 | 476 | if(r < 0) { |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
477 | out->io_errno = errno; |
54 | 478 | return IO_ERROR; |
479 | } | |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
480 | return r; |
54 | 481 | } else { |
66
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
482 | // stream/file does not support sendfile |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
483 | // do regular copy |
112 | 484 | return net_fallback_sendfile(out, sfd); |
54 | 485 | } |
486 | } | |
487 | ||
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
488 | // private |
112 | 489 | ssize_t net_fallback_sendfile(IOStream *fd, sendfiledata *sfd) { |
111
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
490 | char *buf = malloc(4096); |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
491 | if(!buf) { |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
492 | // TODO: out of memory error |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
493 | return IO_ERROR; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
494 | } |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
495 | char *header = (char*)sfd->header; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
496 | int hlen = sfd->hlen; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
497 | char *trailer = (char*)sfd->trailer; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
498 | int tlen = sfd->tlen; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
499 | if(header == NULL) { |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
500 | hlen = 0; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
501 | } |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
502 | if(trailer == NULL) { |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
503 | tlen = 0; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
504 | } |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
505 | |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
506 | ssize_t r; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
507 | while(hlen > 0) { |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
508 | r = fd->write(fd, header, hlen); |
111
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
509 | header += r; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
510 | hlen -= r; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
511 | if(r <= 0) { |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
512 | free(buf); |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
513 | fd->io_errno = errno; |
111
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
514 | return IO_ERROR; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
515 | } |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
516 | } |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
517 | |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
518 | if(system_lseek(sfd->fd, sfd->offset, SEEK_SET) == -1) { |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
519 | free(buf); |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
520 | fd->io_errno = errno; |
111
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
521 | return IO_ERROR; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
522 | } |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
523 | |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
524 | size_t length = sfd->len; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
525 | while(length > 0) { |
205
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
526 | // TODO: remove |
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
527 | if(length > sfd->len) { |
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
528 | log_ereport(LOG_WARN, "net_fallback_sendfile: length > sfd->len: %zu > %zu", length, sfd->len); |
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
529 | free(buf); |
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
530 | return IO_ERROR; |
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
531 | } |
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
532 | |
111
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
533 | if((r = system_fread(sfd->fd, buf, 4096)) <= 0) { |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
534 | break; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
535 | } |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
536 | char *write_buf = buf; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
537 | while(r > 0) { |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
538 | ssize_t w = fd->write(fd, write_buf, r); |
205
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
539 | // TODO: remove |
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
540 | if(w > r) { |
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
541 | log_ereport(LOG_WARN, "net_fallback_sendfile: w > r, %zd > %zd", w, r); |
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
542 | w = 0; |
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
543 | } |
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
544 | |
203
7fe53d5d587c
fix error handling in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
545 | if(w <= 0) { |
205
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
546 | free(buf); |
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
547 | fd->io_errno = errno; |
b8515afa450a
improve error handling and add some debug code in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
548 | return IO_ERROR; |
203
7fe53d5d587c
fix error handling in net_fallback_sendfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
549 | } |
111
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
550 | r -= w; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
551 | length -= w; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
552 | write_buf += w; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
553 | } |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
554 | } |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
555 | free(buf); |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
556 | if(length > 0) { |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
557 | fd->io_errno = errno; |
111
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
558 | return IO_ERROR; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
559 | } |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
560 | |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
561 | while(tlen > 0) { |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
562 | r = fd->write(fd, trailer, tlen); |
111
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
563 | trailer += r; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
564 | tlen -= r; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
565 | if(r <= 0) { |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
566 | fd->io_errno = errno; |
111
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
567 | return IO_ERROR; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
568 | } |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
569 | } |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
570 | |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
571 | return sfd->hlen + sfd->len + sfd->tlen; |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
572 | } |
c93be34fde76
fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
573 | |
82
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
574 | int net_flush(SYS_NETFD sd) { |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
575 | // TODO: implement |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
576 | return 0; |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
577 | } |
32
ebba53de8b18
added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
578 | |
80
0de4a90979e1
fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
579 | void net_close(SYS_NETFD fd) { |
0de4a90979e1
fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
580 | ((IOStream*)fd)->close(fd); |
32
ebba53de8b18
added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
581 | } |
ebba53de8b18
added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
582 | |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
583 | int net_setnonblock(SYS_NETFD fd, int nonblock) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
584 | ((IOStream*)fd)->setmode( |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
585 | fd, |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
586 | nonblock ? IO_MODE_NONBLOCKING : IO_MODE_BLOCKING); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
587 | return 0; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
588 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
589 | |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
590 | int net_errno(SYS_NETFD fd) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
591 | return ((IOStream*)fd)->io_errno; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
592 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
147
diff
changeset
|
593 | |
110
43a746e905f6
refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
594 | // private |
80
0de4a90979e1
fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
595 | void net_finish(SYS_NETFD fd) { |
0de4a90979e1
fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
596 | ((IOStream*)fd)->finish(fd); |
32
ebba53de8b18
added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
597 | } |