add iob_addbuf_munmap
This commit is contained in:
parent
a367678710
commit
527efc70b6
1
CHANGES
1
CHANGES
@ -1,5 +1,6 @@
|
|||||||
0.27:
|
0.27:
|
||||||
add fmt_strm
|
add fmt_strm
|
||||||
|
add iob_addbuf_munmap
|
||||||
|
|
||||||
0.26:
|
0.26:
|
||||||
fix really pathological case where io_timeouted would never
|
fix really pathological case where io_timeouted would never
|
||||||
|
5
io/iob_addbuf_munmap.c
Normal file
5
io/iob_addbuf_munmap.c
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include "iob_internal.h"
|
||||||
|
|
||||||
|
int iob_addbuf_free(io_batch* b,const void* buf,uint64 n) {
|
||||||
|
return iob_addbuf_internal(b,buf,n,2);
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
#include "byte.h"
|
#include "byte.h"
|
||||||
#include "iob_internal.h"
|
#include "iob_internal.h"
|
||||||
|
|
||||||
@ -7,10 +8,18 @@ void iob_reset(io_batch* b) {
|
|||||||
iob_entry* x=array_start(&b->b);
|
iob_entry* x=array_start(&b->b);
|
||||||
l=array_length(&b->b,sizeof(iob_entry));
|
l=array_length(&b->b,sizeof(iob_entry));
|
||||||
for (i=0; i<l; ++i) {
|
for (i=0; i<l; ++i) {
|
||||||
if (x[i].type==FROMBUF_FREE)
|
switch (x[i].type) {
|
||||||
|
case FROMBUF_FREE:
|
||||||
free((char*)x[i].buf);
|
free((char*)x[i].buf);
|
||||||
if (x[i].type==FROMFILE_CLOSE)
|
break;
|
||||||
|
case FROMBUF_MUNMAP:
|
||||||
|
munmap((char*)x[i].buf,x[i].n);
|
||||||
|
break;
|
||||||
|
case FROMFILE_CLOSE:
|
||||||
io_close(x[i].fd);
|
io_close(x[i].fd);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
array_reset(&b->b);
|
array_reset(&b->b);
|
||||||
byte_zero(b,sizeof(*b));
|
byte_zero(b,sizeof(*b));
|
||||||
|
@ -45,7 +45,7 @@ int64 iob_send(int64 s,io_batch* b) {
|
|||||||
for (i=0; x+i<last; ++i)
|
for (i=0; x+i<last; ++i)
|
||||||
if (x[i].n) break;
|
if (x[i].n) break;
|
||||||
|
|
||||||
if (x[i].type==FROMBUF || x[i].type==FROMBUF_FREE) {
|
if (x[i].type==FROMBUF || x[i].type==FROMBUF_FREE || x[i].type==FROMBUF_MUNMAP) {
|
||||||
fprintf(stderr,"found non-sent buffer batch entry at %d\n",i);
|
fprintf(stderr,"found non-sent buffer batch entry at %d\n",i);
|
||||||
if (x+i+1 < last &&
|
if (x+i+1 < last &&
|
||||||
(x[i+1].type==FROMFILE || x[i+1].type==FROMFILE_CLOSE)) {
|
(x[i+1].type==FROMFILE || x[i+1].type==FROMFILE_CLOSE)) {
|
||||||
|
1
iob.h
1
iob.h
@ -24,6 +24,7 @@ typedef struct io_batch {
|
|||||||
io_batch* iob_new(int hint_entries);
|
io_batch* iob_new(int hint_entries);
|
||||||
int iob_addbuf(io_batch* b,const void* buf,uint64 n);
|
int iob_addbuf(io_batch* b,const void* buf,uint64 n);
|
||||||
int iob_addbuf_free(io_batch* b,const void* buf,uint64 n);
|
int iob_addbuf_free(io_batch* b,const void* buf,uint64 n);
|
||||||
|
int iob_addbuf_munmap(io_batch* b,const void* buf,uint64 n);
|
||||||
int iob_adds(io_batch* b,const char* s);
|
int iob_adds(io_batch* b,const char* s);
|
||||||
int iob_adds_free(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(io_batch* b,int64 fd,uint64 off,uint64 n);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "array.h"
|
#include "array.h"
|
||||||
|
|
||||||
typedef struct iob_entry {
|
typedef struct iob_entry {
|
||||||
enum { FROMBUF, FROMBUF_FREE, FROMFILE, FROMFILE_CLOSE } type;
|
enum { FROMBUF, FROMBUF_FREE, FROMBUF_MUNMAP, FROMFILE, FROMFILE_CLOSE } type;
|
||||||
int64 fd;
|
int64 fd;
|
||||||
const char* buf;
|
const char* buf;
|
||||||
uint64 offset,n;
|
uint64 offset,n;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user