10 #include "../layout/dlist.h"
13 OutBuffer *back, *next;
18 static void *writeable(oop_source *evts, int fd,
19 oop_event evt, void *ch_v) {
20 OutBufferChain *ch= ch_v;
25 assert(evt == OOP_WRITE);
30 events->cancel_fd(events, fd, OOP_WRITE);
33 if (ch->done_of_head == ob->l) {
34 LIST_UNLINK(ch->obs, ob);
40 r= write(ch->fd, ob->m + ch->done_of_head, ob->l - ch->done_of_head);
42 if (errno==EINTR) continue;
43 if (errno==EWOULDBLOCK) return OOP_CONTINUE;
44 ch->error(ch,"write",strerror(errno));
47 ch->done_of_head += r;
48 assert(ch->done_of_head <= ob->l);
52 static void addlink(OutBufferChain *ch, OutBuffer *ob) {
54 events->on_fd(events, ch->fd, OOP_WRITE, writeable, ch);
55 LIST_LINK_TAIL(ch->obs, ob);
58 void obc_init(OutBufferChain *ch) {
63 void ovprintf(OutBufferChain *ch, const char *fmt, va_list al) {
66 ob= mmalloc(sizeof(*ob));
67 ob->l= vasprintf(&ob->m, fmt, al); if (ob->l <= 0) diem();
71 void oprintf(OutBufferChain *ch, const char *msg, ...) {
78 void owrite(OutBufferChain *ch, const char *data, int l) {
80 ob= mmalloc(sizeof(*ob));
83 memcpy(ob->m, data, l);