diff --git a/io.h b/io.h index 8ab8432..c151c66 100644 --- a/io.h +++ b/io.h @@ -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) */ diff --git a/io/iob_write.c b/io/iob_write.c index 11019db..dfd4974 100644 --- a/io/iob_write.c +++ b/io/iob_write.c @@ -1,6 +1,6 @@ #include -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); +} diff --git a/iob.h b/iob.h index e04d579..c5b9231 100644 --- a/iob.h +++ b/iob.h @@ -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);