49 } |
51 } |
50 |
52 |
51 ssize_t system_read(IOStream *st, void *buf, size_t nbytes) { |
53 ssize_t system_read(IOStream *st, void *buf, size_t nbytes) { |
52 return read(((SystemIOStream*)st)->fd, buf, nbytes); |
54 return read(((SystemIOStream*)st)->fd, buf, nbytes); |
53 } |
55 } |
|
56 |
|
57 |
|
58 /* iovec buffer */ |
|
59 iovec_buf_t *iovec_buf_create(pool_handle_t *pool) { |
|
60 iovec_buf_t *buf = pool_malloc(pool, sizeof(iovec_buf_t)); |
|
61 |
|
62 buf->pool = pool; |
|
63 buf->iov = pool_calloc(pool, 32, sizeof(struct iovec)); |
|
64 buf->maxiovec = 32; |
|
65 buf->iovctn = 0; |
|
66 |
|
67 return buf; |
|
68 } |
|
69 |
|
70 void iovec_buf_write(iovec_buf_t *io, void *buf, size_t nbyte) { |
|
71 if(io->iovctn >= io->maxiovec) { |
|
72 io->iov = pool_realloc( |
|
73 io->pool, |
|
74 io->iov, |
|
75 (io->maxiovec + 16) * sizeof(struct iovec)); |
|
76 } |
|
77 |
|
78 io->iov[io->iovctn].iov_base = buf; |
|
79 io->iov[io->iovctn].iov_len = nbyte; |
|
80 io->iovctn++; |
|
81 } |
|
82 |
|
83 ssize_t iovec_buf_flush(iovec_buf_t *io, int fd) { |
|
84 return writev(fd, io->iov, io->iovctn); |
|
85 } |