add iob_addfile_close (iob_reset will close the files)
This commit is contained in:
parent
6ad2022cad
commit
3996ade63e
15
io/iob_addfile_close.c
Normal file
15
io/iob_addfile_close.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include "iob_internal.h"
|
||||
|
||||
int iob_addfile_close(io_batch* b,int64 fd,uint64 off,uint64 n) {
|
||||
iob_entry* e=array_allocate(&b->b,sizeof(iob_entry),
|
||||
array_length(&b->b,sizeof(iob_entry)));
|
||||
if (!e) return 0;
|
||||
e->type=FROMFILE_CLOSE;
|
||||
e->fd=fd;
|
||||
e->buf=0;
|
||||
e->n=n;
|
||||
e->offset=off;
|
||||
b->bytesleft+=n;
|
||||
++b->files;
|
||||
return 1;
|
||||
}
|
@ -11,7 +11,7 @@ void iob_prefetch(io_batch* b,uint64 bytes) {
|
||||
e=(iob_entry*)array_start(&b->b);
|
||||
if (!e) return;
|
||||
for (; e<last; ++e) {
|
||||
if (e->type==FROMFILE) {
|
||||
if (e->type==FROMFILE || e->type==FROMFILE_CLOSE) {
|
||||
char* c,* d;
|
||||
uint64 before=bytes;
|
||||
if (e->n<bytes) bytes=e->n;
|
||||
|
@ -9,6 +9,8 @@ void iob_reset(io_batch* b) {
|
||||
for (i=0; i<l; ++i) {
|
||||
if (x[i].type==FROMBUF_FREE)
|
||||
free((char*)x[i].buf);
|
||||
if (x[i].type==FROMFILE_CLOSE)
|
||||
io_close(x[i].fd);
|
||||
}
|
||||
array_reset(&b->b);
|
||||
byte_zero(b,sizeof(*b));
|
||||
|
@ -36,18 +36,18 @@ int64 iob_send(int64 s,io_batch* b) {
|
||||
headers=trailers=0;
|
||||
#endif
|
||||
for (i=0; e+i<last; ++i) {
|
||||
if (e[i].type==FROMFILE) break;
|
||||
if (e[i].type==FROMFILE || e[i].type==FROMFILE_CLOSE) break;
|
||||
v[i].iov_base=(char*)(e[i].buf+e[i].offset);
|
||||
v[i].iov_len=e[i].n;
|
||||
}
|
||||
headers=i;
|
||||
#ifdef HAVE_BSDSENDFILE
|
||||
if (e[i].type==FROMFILE) {
|
||||
if (e[i].type==FROMFILE || e[i].type==FROMFILE_CLOSE) {
|
||||
off_t sbytes;
|
||||
struct sf_hdtr hdr;
|
||||
int r;
|
||||
for (++i; e+i<last; ++i) {
|
||||
if (e[i].type==FROMFILE) break;
|
||||
if (e[i].type==FROMFILE || e[i].type==FROMFILE_CLOSE) break;
|
||||
v[i-1].iov_base=(char*)(e[i].buf+e[i].offset);
|
||||
v[i-1].iov_len=e[i].n;
|
||||
++trailers;
|
||||
|
1
iob.h
1
iob.h
@ -27,6 +27,7 @@ int iob_addbuf_free(io_batch* b,const void* buf,uint64 n);
|
||||
int iob_adds(io_batch* b,const char* s);
|
||||
int iob_adds_free(io_batch* b,const char* s);
|
||||
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);
|
||||
void iob_reset(io_batch* b);
|
||||
void iob_prefetch(io_batch* b,uint64 bytes);
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "array.h"
|
||||
|
||||
typedef struct iob_entry {
|
||||
enum { FROMBUF, FROMBUF_FREE, FROMFILE } type;
|
||||
enum { FROMBUF, FROMBUF_FREE, FROMFILE, FROMFILE_CLOSE } type;
|
||||
int64 fd;
|
||||
const char* buf;
|
||||
uint64 offset,n;
|
||||
|
Loading…
x
Reference in New Issue
Block a user