add iob_adds
add cookies to io
This commit is contained in:
parent
c2453002d3
commit
ea8e1cc90b
3
io.h
3
io.h
@ -56,6 +56,9 @@ int64 io_timeouted();
|
|||||||
/* put d on internal data structure, return 1 on success, 0 on error */
|
/* put d on internal data structure, return 1 on success, 0 on error */
|
||||||
int io_fd(int64 d);
|
int io_fd(int64 d);
|
||||||
|
|
||||||
|
void io_setcookie(int64 d,void* cookie);
|
||||||
|
void* io_getcookie(int64 d);
|
||||||
|
|
||||||
/* put descriptor in non-blocking mode */
|
/* put descriptor in non-blocking mode */
|
||||||
void io_nonblock(int64 d);
|
void io_nonblock(int64 d);
|
||||||
/* put descriptor in close-on-exec mode */
|
/* put descriptor in close-on-exec mode */
|
||||||
|
8
io/io_getcookie.c
Normal file
8
io/io_getcookie.c
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <unistd.h>
|
||||||
|
#include "io_internal.h"
|
||||||
|
|
||||||
|
void* io_getcookie(int64 d) {
|
||||||
|
io_entry* e;
|
||||||
|
e=array_get(&io_fds,sizeof(io_entry),d);
|
||||||
|
return e?e->cookie:0;
|
||||||
|
}
|
9
io/io_setcookie.c
Normal file
9
io/io_setcookie.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "io_internal.h"
|
||||||
|
|
||||||
|
void io_setcookie(int64 d,void* cookie) {
|
||||||
|
io_entry* e;
|
||||||
|
if ((e=array_get(&io_fds,sizeof(io_entry),d)))
|
||||||
|
e->cookie=cookie;
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#include "iob_internal.h"
|
#include "iob_internal.h"
|
||||||
|
|
||||||
int iob_addbuf(io_batch* b,void* buf,uint64 n) {
|
int iob_addbuf(io_batch* b,const void* buf,uint64 n) {
|
||||||
io_entry* e=array_allocate(&b->b,sizeof(io_entry),
|
io_entry* e=array_allocate(&b->b,sizeof(io_entry),
|
||||||
array_length(&b->b,sizeof(io_entry)));
|
array_length(&b->b,sizeof(io_entry)));
|
||||||
if (!e) return 0;
|
if (!e) return 0;
|
||||||
|
6
io/iob_adds.c
Normal file
6
io/iob_adds.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "str.h"
|
||||||
|
#include "iob.h"
|
||||||
|
|
||||||
|
int iob_adds(io_batch* b,const char* s) {
|
||||||
|
return iob_addbuf(b,s,str_len(s));
|
||||||
|
}
|
@ -38,7 +38,7 @@ int64 iob_send(int64 s,io_batch* b) {
|
|||||||
#endif
|
#endif
|
||||||
for (i=0; e+i<last; ++i) {
|
for (i=0; e+i<last; ++i) {
|
||||||
if (e[i].type==FROMFILE) break;
|
if (e[i].type==FROMFILE) break;
|
||||||
v[i].iov_base=e[i].buf+e[i].offset;
|
v[i].iov_base=(char*)(e[i].buf+e[i].offset);
|
||||||
v[i].iov_len=e[i].n-e[i].offset;
|
v[i].iov_len=e[i].n-e[i].offset;
|
||||||
}
|
}
|
||||||
headers=i;
|
headers=i;
|
||||||
@ -49,7 +49,7 @@ int64 iob_send(int64 s,io_batch* b) {
|
|||||||
int r;
|
int r;
|
||||||
for (++i; e+i<last; ++i) {
|
for (++i; e+i<last; ++i) {
|
||||||
if (e[i].type==FROMFILE) break;
|
if (e[i].type==FROMFILE) break;
|
||||||
v[i-1].iov_base=e[i].buf+e[i].offset;
|
v[i-1].iov_base=(char*)(e[i].buf+e[i].offset);
|
||||||
v[i-1].iov_len=e[i].n-e[i].offset;
|
v[i-1].iov_len=e[i].n-e[i].offset;
|
||||||
++trailers;
|
++trailers;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ typedef struct {
|
|||||||
tai6464 timeout;
|
tai6464 timeout;
|
||||||
long next_read;
|
long next_read;
|
||||||
long next_write;
|
long next_write;
|
||||||
|
void* cookie;
|
||||||
} io_entry;
|
} io_entry;
|
||||||
|
|
||||||
array io_fds;
|
array io_fds;
|
||||||
|
3
iob.h
3
iob.h
@ -17,7 +17,8 @@
|
|||||||
typedef struct io_batch io_batch;
|
typedef struct io_batch io_batch;
|
||||||
|
|
||||||
io_batch* iob_new(int hint_entries);
|
io_batch* iob_new(int hint_entries);
|
||||||
int iob_addbuf(io_batch* b,void* buf,uint64 n);
|
int iob_addbuf(io_batch* b,const void* buf,uint64 n);
|
||||||
|
int iob_adds(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);
|
||||||
int64 iob_send(int64 s,io_batch* b);
|
int64 iob_send(int64 s,io_batch* b);
|
||||||
void iob_reset(io_batch* b);
|
void iob_reset(io_batch* b);
|
||||||
|
@ -10,6 +10,6 @@ struct io_batch {
|
|||||||
typedef struct io_entry {
|
typedef struct io_entry {
|
||||||
enum { FROMBUF, FROMFILE } type;
|
enum { FROMBUF, FROMFILE } type;
|
||||||
int64 fd;
|
int64 fd;
|
||||||
char* buf;
|
const char* buf;
|
||||||
uint64 offset,n;
|
uint64 offset,n;
|
||||||
} io_entry;
|
} io_entry;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user