10 #include "../layout/dlist.h"
12 static void *writeable(oop_source *evts, int fd,
13 oop_event evt, void *ch_v) {
14 OutBufferChain *ch= ch_v;
19 assert(evt == OOP_WRITE);
24 events->cancel_fd(events, fd, OOP_WRITE);
27 if (ch->done_of_head == ob->l) {
28 LIST_UNLINK(ch->obs, ob);
34 r= write(ch->fd, ob->m + ch->done_of_head, ob->l - ch->done_of_head);
36 if (errno==EINTR) continue;
37 if (errno==EWOULDBLOCK) return OOP_CONTINUE;
38 ch->error(ch,"write",strerror(errno));
41 ch->done_of_head += r;
42 assert(ch->done_of_head <= ob->l);
46 static void addlink(OutBufferChain *ch, OutBuffer *ob) {
48 events->on_fd(events, ch->fd, OOP_WRITE, writeable, ch);
49 LIST_LINK_TAIL(ch->obs, ob);
52 void obc_init(OutBufferChain *ch) {
57 void ovprintf(OutBufferChain *ch, const char *fmt, va_list al) {
60 ob= mmalloc(sizeof(*ob));
61 ob->l= vasprintf(&ob->m, fmt, al); if (ob->l <= 0) diem();
65 void oprintf(OutBufferChain *ch, const char *msg, ...) {
72 void owrite(OutBufferChain *ch, const char *data, int l) {
74 ob= mmalloc(sizeof(*ob));
77 memcpy(ob->m, data, l);