50 return write(((SystemIOStream*)st)->fd, buf, nbytes); |
55 return write(((SystemIOStream*)st)->fd, buf, nbytes); |
51 } |
56 } |
52 |
57 |
53 ssize_t system_read(IOStream *st, void *buf, size_t nbytes) { |
58 ssize_t system_read(IOStream *st, void *buf, size_t nbytes) { |
54 return read(((SystemIOStream*)st)->fd, buf, nbytes); |
59 return read(((SystemIOStream*)st)->fd, buf, nbytes); |
|
60 } |
|
61 |
|
62 |
|
63 IOStream* net_stream_from_fd(int fd) { |
|
64 NetIOStream *st = malloc(sizeof(NetIOStream)); |
|
65 st->st = net_io_funcs; |
|
66 st->fd = fd; |
|
67 st->max_read = 0; |
|
68 st->rd = 0; |
|
69 } |
|
70 |
|
71 ssize_t net_stream_write(IOStream *st, void *buf, size_t nbytes) { |
|
72 // TODO: implement |
|
73 } |
|
74 |
|
75 ssize_t net_stream_read(IOStream *st, void *buf, size_t nbytes) { |
|
76 NetIOStream *n = (NetIOStream*)st; |
|
77 if(n->max_read != 0 && n->rd >= n->max_read) { |
|
78 return 0; |
|
79 } |
|
80 ssize_t r = read(n->fd, buf, nbytes); |
|
81 n->rd += r; |
|
82 return r; |
|
83 } |
|
84 |
|
85 |
|
86 ssize_t net_read(SYS_NETFD fd, void *buf, size_t nbytes) { |
|
87 ssize_t r = ((IOStream*)fd)->read(fd, buf, nbytes); |
|
88 if(r == 0) { |
|
89 return IO_EOF; |
|
90 } |
|
91 return r; |
55 } |
92 } |
56 |
93 |
57 |
94 |
58 /* iovec buffer */ |
95 /* iovec buffer */ |
59 iovec_buf_t *iovec_buf_create(pool_handle_t *pool) { |
96 iovec_buf_t *iovec_buf_create(pool_handle_t *pool) { |