From 122c246222afdefdc2d50fdbac6f867849a33d5f Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Mon, 25 Apr 2016 15:08:14 +0200 Subject: [PATCH] lib: Added mtio-driven bufio implementation. --- lib/mtio.c | 28 ++++++++++++++++++++++++++++ lib/mtio.h | 1 + 2 files changed, 29 insertions(+) diff --git a/lib/mtio.c b/lib/mtio.c index d7f36ac..183f9f2 100644 --- a/lib/mtio.c +++ b/lib/mtio.c @@ -121,6 +121,34 @@ FILE *mtstdopen(int fd, int issock, int timeout, char *mode, struct stdiofd **in return(ret); } +struct bufio *mtbioopen(int fd, int issock, int timeout, char *mode, struct stdiofd **infop) +{ + static struct bufioops ops = { + .read = mtread, .write = mtwrite, .close = mtclose, + }; + struct stdiofd *d; + struct bufio *ret; + + if(!strcmp(mode, "r")) { + } else if(!strcmp(mode, "w")) { + } else if(!strcmp(mode, "r+")) { + } else { + return(NULL); + } + omalloc(d); + d->fd = fd; + d->sock = issock; + d->timeout = timeout; + if(!(ret = bioopen(d, &ops))) { + free(d); + return(NULL); + } + fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); + if(infop) + *infop = d; + return(ret); +} + struct pipe { struct charbuf data; size_t bufmax; diff --git a/lib/mtio.h b/lib/mtio.h index 75928eb..f6611df 100644 --- a/lib/mtio.h +++ b/lib/mtio.h @@ -16,6 +16,7 @@ int block(int fd, int ev, time_t to); int ioloop(void); void exitioloop(int status); FILE *mtstdopen(int fd, int issock, int timeout, char *mode, struct stdiofd **infop); +struct bufio *mtbioopen(int fd, int issock, int timeout, char *mode, struct stdiofd **infop); void mtiopipe(FILE **read, FILE **write); #endif -- 2.11.0