add iob_write (to write an io batch through a callback)
parent
ccba2abe9b
commit
b48ce77792
@ -0,0 +1,5 @@
|
|||||||
|
#include <buffer.h>
|
||||||
|
|
||||||
|
int buffer_getline(buffer* b,unsigned char* x,unsigned long int len) {
|
||||||
|
return buffer_get_token(b,x,len,"\n",1);
|
||||||
|
}
|
@ -1,17 +1,24 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "iob.h"
|
#include "iob.h"
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static int64 write_cb(int64 fd,const void* buf,uint64 len) {
|
||||||
|
if (len>2) len=2;
|
||||||
|
return write(fd,buf,len);
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int64 fd;
|
int64 fd;
|
||||||
io_batch* b;
|
io_batch* b;
|
||||||
|
int64 r;
|
||||||
assert(io_readfile(&fd,"GNUmakefile"));
|
assert(io_readfile(&fd,"GNUmakefile"));
|
||||||
assert(b=iob_new(10));
|
assert(b=iob_new(10));
|
||||||
assert(iob_addbuf(b,"Huhu",4));
|
assert(iob_addbuf(b,"Huhu",4));
|
||||||
assert(iob_addbuf(b," fnord\n",7));
|
assert(iob_addbuf(b," fnord\n",7));
|
||||||
assert(iob_addfile(b,fd,10,10));
|
assert(iob_addfile(b,fd,10,10));
|
||||||
buffer_puts(buffer_2,"iob_send returned ");
|
do {
|
||||||
buffer_putlong(buffer_2,iob_send(1,b));
|
r=iob_write(1,b,write_cb);
|
||||||
buffer_putsflush(buffer_2,".\n");
|
} while (r>0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue