add iob_adds

add cookies to io
master
leitner 22 years ago
parent c2453002d3
commit ea8e1cc90b

@ -56,6 +56,9 @@ int64 io_timeouted();
/* put d on internal data structure, return 1 on success, 0 on error */
int io_fd(int64 d);
void io_setcookie(int64 d,void* cookie);
void* io_getcookie(int64 d);
/* put descriptor in non-blocking mode */
void io_nonblock(int64 d);
/* put descriptor in close-on-exec mode */

@ -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;
}

@ -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"
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),
array_length(&b->b,sizeof(io_entry)));
if (!e) return 0;

@ -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
for (i=0; e+i<last; ++i) {
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;
}
headers=i;
@ -49,7 +49,7 @@ int64 iob_send(int64 s,io_batch* b) {
int r;
for (++i; e+i<last; ++i) {
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;
++trailers;
}

@ -13,6 +13,7 @@ typedef struct {
tai6464 timeout;
long next_read;
long next_write;
void* cookie;
} io_entry;
array io_fds;

@ -17,7 +17,8 @@
typedef struct io_batch io_batch;
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);
int64 iob_send(int64 s,io_batch* b);
void iob_reset(io_batch* b);

@ -10,6 +10,6 @@ struct io_batch {
typedef struct io_entry {
enum { FROMBUF, FROMFILE } type;
int64 fd;
char* buf;
const char* buf;
uint64 offset,n;
} io_entry;

Loading…
Cancel
Save