From ea8e1cc90b198dfdc4f7e2ab80d573cf228447ec Mon Sep 17 00:00:00 2001 From: leitner Date: Wed, 10 Sep 2003 00:28:51 +0000 Subject: [PATCH] add iob_adds add cookies to io --- io.h | 3 +++ io/io_getcookie.c | 8 ++++++++ io/io_setcookie.c | 9 +++++++++ io/iob_addbuf.c | 2 +- io/iob_adds.c | 6 ++++++ io/iob_send.c | 4 ++-- io_internal.h | 1 + iob.h | 3 ++- iob_internal.h | 2 +- 9 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 io/io_getcookie.c create mode 100644 io/io_setcookie.c create mode 100644 io/iob_adds.c diff --git a/io.h b/io.h index 880e7e3..f4fcb3d 100644 --- a/io.h +++ b/io.h @@ -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 */ diff --git a/io/io_getcookie.c b/io/io_getcookie.c new file mode 100644 index 0000000..40f55d6 --- /dev/null +++ b/io/io_getcookie.c @@ -0,0 +1,8 @@ +#include +#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; +} diff --git a/io/io_setcookie.c b/io/io_setcookie.c new file mode 100644 index 0000000..46cb6d7 --- /dev/null +++ b/io/io_setcookie.c @@ -0,0 +1,9 @@ + +#include +#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; +} diff --git a/io/iob_addbuf.c b/io/iob_addbuf.c index 3963555..d4a49be 100644 --- a/io/iob_addbuf.c +++ b/io/iob_addbuf.c @@ -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; diff --git a/io/iob_adds.c b/io/iob_adds.c new file mode 100644 index 0000000..7441ab9 --- /dev/null +++ b/io/iob_adds.c @@ -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)); +} diff --git a/io/iob_send.c b/io/iob_send.c index 56e9a08..2989862 100644 --- a/io/iob_send.c +++ b/io/iob_send.c @@ -38,7 +38,7 @@ int64 iob_send(int64 s,io_batch* b) { #endif for (i=0; e+i