add iob_write2 which takes an additional sendfile callback

master
leitner 2 years ago
parent 7b4391d263
commit 00bc4e4a5d

@ -197,6 +197,7 @@ int io_queueforread(int64 d);
int io_queueforwrite(int64 d);
typedef int64 (*io_write_callback)(int64 s,const void* buf,uint64 n);
typedef int64 (*io_sendfile_callback)(int64 out,int64 in,uint64 off,uint64 bytes,io_write_callback writecb);
/* used internally, but hey, who knows */
/* sandboxing: write(2), mmap(2), munmap(2), lseek(2), pread(2), read(2), linux: epoll_ctl(2), bsd: kevent(2), solaris: write(2), oldlinux: poll(2) */

@ -1,6 +1,6 @@
#include <iob_internal.h>
int64 iob_write(int64 s,io_batch* b,io_write_callback cb) {
int64 iob_write2(int64 s,io_batch* b,io_write_callback cb,io_sendfile_callback sfcb) {
iob_entry* e,* last;
uint64 total;
int64 sent;
@ -15,7 +15,7 @@ int64 iob_write(int64 s,io_batch* b,io_write_callback cb) {
int thatsit;
if (!e[i].n) continue;
if (e[i].type==FROMFILE)
sent=io_mmapwritefile(s,e[i].fd,e[i].offset,e[i].n,cb);
sent=sfcb(s,e[i].fd,e[i].offset,e[i].n,cb);
else
sent=cb(s,e[i].buf+e[i].offset,e[i].n);
if (sent>0 && (uint64)sent>e[i].n) sent=e[i].n; /* can't happen */
@ -32,3 +32,7 @@ int64 iob_write(int64 s,io_batch* b,io_write_callback cb) {
iob_reset(b);
return total;
}
int64 iob_write(int64 s,io_batch* b,io_write_callback cb) {
return iob_write2(s,b,cb,io_mmapwritefile);
}

@ -47,6 +47,7 @@ int iob_addfile(io_batch* b,int64 fd,uint64 off,uint64 n);
int iob_addfile_close(io_batch* b,int64 fd,uint64 off,uint64 n);
int64 iob_send(int64 s,io_batch* b);
int64 iob_write(int64 s,io_batch* b,io_write_callback cb);
int64 iob_write2(int64 s,io_batch* b,io_write_callback cb,io_sendfile_callback sfcb);
void iob_reset(io_batch* b);
void iob_free(io_batch* b);
void iob_prefetch(io_batch* b,uint64 bytes);

Loading…
Cancel
Save