30 #define _GNU_SOURCE |
30 #define _GNU_SOURCE |
31 #endif |
31 #endif |
32 |
32 |
33 #include <unistd.h> |
33 #include <unistd.h> |
34 #include <stdlib.h> |
34 #include <stdlib.h> |
|
35 |
|
36 #ifdef XP_UNIX |
35 #include <sys/uio.h> |
37 #include <sys/uio.h> |
36 #include <sys/uio.h> |
38 #include <sys/uio.h> |
|
39 #endif |
|
40 |
|
41 #ifdef XP_WIN32 |
|
42 |
|
43 #endif |
37 |
44 |
38 #if defined(LINUX) || defined(SOLARIS) |
45 #if defined(LINUX) || defined(SOLARIS) |
39 #include <sys/sendfile.h> |
46 #include <sys/sendfile.h> |
40 #define WS_SENDFILE |
47 #define WS_SENDFILE |
41 #elif defined(BSD) |
48 #elif defined(BSD) |
42 #if defined(__NetBSD__) || defined(__OpenBSD__) |
49 #if defined(__NetBSD__) || defined(__OpenBSD__) |
43 #define net_sys_sendfile net_fallback_sendfile |
50 #define net_sys_sendfile net_fallback_sendfile |
44 #else |
51 #else |
45 #define WS_SENDFILE |
52 #define WS_SENDFILE |
46 #endif |
53 #endif |
|
54 #endif |
|
55 |
|
56 #ifdef WS_SENDFILE |
|
57 #define NET_SYS_SENDFILE net_sys_sendfile |
47 #else |
58 #else |
48 #define net_sys_sendfile net_fallback_sendfile |
59 #define NET_SYS_SENDFILE net_fallback_sendfile |
49 #endif |
60 #endif |
|
61 |
|
62 |
50 |
63 |
51 #include "../daemon/vfs.h" |
64 #include "../daemon/vfs.h" |
52 #include "io.h" |
65 #include "io.h" |
53 #include "pool.h" |
66 #include "pool.h" |
54 #include "ucx/utils.h" |
67 #include "ucx/utils.h" |
55 |
68 |
56 IOStream native_io_funcs = { |
69 IOStream native_io_funcs = { |
57 (io_write_f)net_sys_write, |
70 (io_write_f)net_sys_write, |
58 (io_writev_f)net_sys_writev, |
71 (io_writev_f)net_sys_writev, |
59 (io_read_f)net_sys_read, |
72 (io_read_f)net_sys_read, |
60 (io_sendfile_f)net_sys_sendfile, |
73 (io_sendfile_f)NET_SYS_SENDFILE, |
61 (io_close_f)net_sys_close, |
74 (io_close_f)net_sys_close, |
62 NULL |
75 NULL |
63 }; |
76 }; |
64 |
77 |
65 IOStream http_io_funcs = { |
78 IOStream http_io_funcs = { |
83 |
96 |
84 /* |
97 /* |
85 * SysStream implementation |
98 * SysStream implementation |
86 */ |
99 */ |
87 |
100 |
88 IOStream* sysstream_new(pool_handle_t *pool, int fd) { |
101 IOStream* sysstream_new(pool_handle_t *pool, SYS_SOCKET fd) { |
89 SysStream *st = pool_malloc(pool, sizeof(SysStream)); |
102 SysStream *st = pool_malloc(pool, sizeof(SysStream)); |
90 st->st = native_io_funcs; |
103 st->st = native_io_funcs; |
91 st->fd = fd; |
104 st->fd = fd; |
92 return (IOStream*)st; |
105 return (IOStream*)st; |
93 } |
106 } |
158 } |
171 } |
159 |
172 |
160 #elif defined(XP_WIN32) |
173 #elif defined(XP_WIN32) |
161 |
174 |
162 ssize_t net_sys_write(SysStream *st, void *buf, size_t nbytes) { |
175 ssize_t net_sys_write(SysStream *st, void *buf, size_t nbytes) { |
163 int ret = send(st->socket, buf, nbytes, 0); |
176 int ret = send(st->fd, buf, nbytes, 0); |
164 if(ret == SOCKET_ERROR) { |
177 if(ret == SOCKET_ERROR) { |
165 return IO_ERROR; |
178 return IO_ERROR; |
166 } |
179 } |
167 return ret; |
180 return ret; |
168 } |
181 } |
170 ssize_t net_sys_writev(SysStream *st, struct iovec *iovec, int iovcnt) { |
183 ssize_t net_sys_writev(SysStream *st, struct iovec *iovec, int iovcnt) { |
171 // TODO |
184 // TODO |
172 } |
185 } |
173 |
186 |
174 ssize_t net_sys_read(SysStream *st, void *buf, size_t nbytes) { |
187 ssize_t net_sys_read(SysStream *st, void *buf, size_t nbytes) { |
175 int ret = recv(st->socket, buf, nbytes, 0); |
188 int ret = recv(st->fd, buf, nbytes, 0); |
176 if(ret == SOCKET_ERROR) { |
189 if(ret == SOCKET_ERROR) { |
177 return IO_ERROR; |
190 return IO_ERROR; |
178 } |
191 } |
179 return ret; |
192 return ret; |
180 } |
193 } |