105 0 |
105 0 |
106 }; |
106 }; |
107 |
107 |
108 |
108 |
109 /* |
109 /* |
110 * Sycx_stream implementation |
110 * Sysstream implementation |
111 */ |
111 */ |
112 |
112 |
113 IOStream* sycx_stream_new(pool_handle_t *pool, SYS_SOCKET fd) { |
113 IOStream* Sysstream_new(pool_handle_t *pool, SYS_SOCKET fd) { |
114 Sycx_stream *st = pool_malloc(pool, sizeof(Sycx_stream)); |
114 Sysstream *st = pool_malloc(pool, sizeof(Sysstream)); |
115 st->st = native_io_funcs; |
115 st->st = native_io_funcs; |
116 st->fd = fd; |
116 st->fd = fd; |
117 return (IOStream*)st; |
117 return (IOStream*)st; |
118 } |
118 } |
119 |
119 |
120 #ifdef XP_UNIX |
120 #ifdef XP_UNIX |
121 ssize_t net_sys_write(Sycx_stream *st, void *buf, size_t nbytes) { |
121 ssize_t net_sys_write(Sysstream *st, void *buf, size_t nbytes) { |
122 return write(st->fd, buf, nbytes); |
122 return write(st->fd, buf, nbytes); |
123 } |
123 } |
124 |
124 |
125 ssize_t net_sys_writev(Sycx_stream *st, struct iovec *iovec, int iovcnt) { |
125 ssize_t net_sys_writev(Sysstream *st, struct iovec *iovec, int iovcnt) { |
126 return writev(st->fd, iovec, iovcnt); |
126 return writev(st->fd, iovec, iovcnt); |
127 } |
127 } |
128 |
128 |
129 ssize_t net_sys_read(Sycx_stream *st, void *buf, size_t nbytes) { |
129 ssize_t net_sys_read(Sysstream *st, void *buf, size_t nbytes) { |
130 return read(st->fd, buf, nbytes); |
130 return read(st->fd, buf, nbytes); |
131 } |
131 } |
132 |
132 |
133 #ifdef WS_SENDFILE |
133 #ifdef WS_SENDFILE |
134 ssize_t net_sys_sendfile(Sycx_stream *st, sendfiledata *sfd) { |
134 ssize_t net_sys_sendfile(Sysstream *st, sendfiledata *sfd) { |
135 ssize_t ret = 0; |
135 ssize_t ret = 0; |
136 off_t fileoffset = sfd->offset; |
136 off_t fileoffset = sfd->offset; |
137 if(sfd->fd->fd != -1) { |
137 if(sfd->fd->fd != -1) { |
138 #ifdef BSD |
138 #ifdef BSD |
139 struct iovec hdvec; |
139 struct iovec hdvec; |
176 |
176 |
177 return ret; |
177 return ret; |
178 } |
178 } |
179 #endif |
179 #endif |
180 |
180 |
181 void net_sys_close(Sycx_stream *st) { |
181 void net_sys_close(Sysstream *st) { |
182 system_close(st->fd); |
182 system_close(st->fd); |
183 } |
183 } |
184 |
184 |
185 void net_sys_setmode(Sycx_stream *st, int mode) { |
185 void net_sys_setmode(Sysstream *st, int mode) { |
186 int flags; |
186 int flags; |
187 if (-1 == (flags = fcntl(st->fd, F_GETFL, 0))) { |
187 if (-1 == (flags = fcntl(st->fd, F_GETFL, 0))) { |
188 flags = 0; |
188 flags = 0; |
189 } |
189 } |
190 if(mode == IO_MODE_BLOCKING) { |
190 if(mode == IO_MODE_BLOCKING) { |
198 // TODO: error |
198 // TODO: error |
199 } |
199 } |
200 } |
200 } |
201 } |
201 } |
202 |
202 |
203 int net_sys_poll(Sycx_stream *st, EventHandler *ev, int events, Event *cb) { |
203 int net_sys_poll(Sysstream *st, EventHandler *ev, int events, Event *cb) { |
204 switch(events) { |
204 switch(events) { |
205 default: return -1; |
205 default: return -1; |
206 case IO_POLL_NONE: return ev_remove_poll(ev, st->fd); |
206 case IO_POLL_NONE: return ev_remove_poll(ev, st->fd); |
207 case IO_POLL_IN: return ev_pollin(ev, st->fd, cb); |
207 case IO_POLL_IN: return ev_pollin(ev, st->fd, cb); |
208 case IO_POLL_OUT: return ev_pollout(ev, st->fd, cb); |
208 case IO_POLL_OUT: return ev_pollout(ev, st->fd, cb); |
210 } |
210 } |
211 } |
211 } |
212 |
212 |
213 #elif defined(XP_WIN32) |
213 #elif defined(XP_WIN32) |
214 |
214 |
215 ssize_t net_sys_write(Sycx_stream *st, void *buf, size_t nbytes) { |
215 ssize_t net_sys_write(Sysstream *st, void *buf, size_t nbytes) { |
216 int ret = send(st->fd, buf, nbytes, 0); |
216 int ret = send(st->fd, buf, nbytes, 0); |
217 if(ret == SOCKET_ERROR) { |
217 if(ret == SOCKET_ERROR) { |
218 return IO_ERROR; |
218 return IO_ERROR; |
219 } |
219 } |
220 return ret; |
220 return ret; |
221 } |
221 } |
222 |
222 |
223 ssize_t net_sys_writev(Sycx_stream *st, struct iovec *iovec, int iovcnt) { |
223 ssize_t net_sys_writev(Sysstream *st, struct iovec *iovec, int iovcnt) { |
224 // TODO |
224 // TODO |
225 } |
225 } |
226 |
226 |
227 ssize_t net_sys_read(Sycx_stream *st, void *buf, size_t nbytes) { |
227 ssize_t net_sys_read(Sysstream *st, void *buf, size_t nbytes) { |
228 int ret = recv(st->fd, buf, nbytes, 0); |
228 int ret = recv(st->fd, buf, nbytes, 0); |
229 if(ret == SOCKET_ERROR) { |
229 if(ret == SOCKET_ERROR) { |
230 return IO_ERROR; |
230 return IO_ERROR; |
231 } |
231 } |
232 return ret; |
232 return ret; |
233 } |
233 } |
234 |
234 |
235 ssize_t net_sys_sendfile(Sycx_stream *st, sendfiledata *sfd) { |
235 ssize_t net_sys_sendfile(Sysstream *st, sendfiledata *sfd) { |
236 // TODO |
236 // TODO |
237 } |
237 } |
238 |
238 |
239 void net_sys_close(Sycx_stream *st) { |
239 void net_sys_close(Sysstream *st) { |
240 closesocket(st->fd); |
240 closesocket(st->fd); |
241 } |
241 } |
242 |
242 |
243 #endif |
243 #endif |
244 |
244 |