Browse Source

add iob_adds

add cookies to io
master
Felix von Leitner 17 years ago
parent
commit
c50a0b25df
9 changed files with 33 additions and 5 deletions
  1. +3
    -0
      io.h
  2. +8
    -0
      io/io_getcookie.c
  3. +9
    -0
      io/io_setcookie.c
  4. +1
    -1
      io/iob_addbuf.c
  5. +6
    -0
      io/iob_adds.c
  6. +2
    -2
      io/iob_send.c
  7. +1
    -0
      io_internal.h
  8. +2
    -1
      iob.h
  9. +1
    -1
      iob_internal.h

+ 3
- 0
io.h View File

@@ -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 */


+ 8
- 0
io/io_getcookie.c View 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
- 0
io/io_setcookie.c View 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
- 1
io/iob_addbuf.c View File

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


+ 6
- 0
io/iob_adds.c View 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));
}

+ 2
- 2
io/iob_send.c View File

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


+ 1
- 0
io_internal.h View File

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

array io_fds;


+ 2
- 1
iob.h View File

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


+ 1
- 1
iob_internal.h View File

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