diff --git a/src/lib/in.c b/src/lib/in.c index 87d04279e..6443e0e34 100644 --- a/src/lib/in.c +++ b/src/lib/in.c @@ -1,5 +1,6 @@ #include #include "internal.h" +#include "in.h" // data collected from responses to our terminal queries. typedef struct termqueries { @@ -27,15 +28,18 @@ typedef struct inputctx { #endif unsigned char ibuf[BUFSIZ]; // we dump raw reads into this ringbuffer, and // process them all post-read + int ibufvalid, ibufwrite; // our bookkeeping for ibuf; + // we mustn't read() if ibufvalid == sizeof(ibuf) cursorloc* csrs; // cursor reports are dumped here ncinput* inputs; // processed input is dumped here int csize, isize; // total number of slots in csrs/inputs int cvalid, ivalid; // population count of csrs/inputs int cwrite, iwrite; // slot where we'll write the next csr/input; // we cannot write if valid == size - int cread, iread; // slot from which to read the next csr/input; - // we cannot read if valid == 0 + int cread, iread; // slot from which clients read the next csr/input; + // they cannot read if valid == 0 tinfo* ti; // link back to tinfo + pthread_t tid; // tid for input thread } inputctx; static inline inputctx* @@ -51,6 +55,7 @@ create_inputctx(tinfo* ti){ i->cvalid = i->ivalid = 0; i->cwrite = i->iwrite = 0; i->cread = i->iread = 0; + i->ibufvalid = i->ibufwrite = 0; return i; } free(i->csrs); @@ -69,3 +74,34 @@ free_inputctx(inputctx* i){ free(i); } } + +static void* +input_thread(void* vmarshall){ + inputctx* ictx = vmarshall; + for(;;){ + if(ictx->ibufvalid == sizeof(ictx->ibuf)){ + // we can't read any more. need clients to clear their buffers. + // sleep on condvar FIXME + } + } + return NULL; +} + +int init_inputlayer(tinfo* ti){ + inputctx* ictx = create_inputctx(ti); + if(ictx == NULL){ + return -1; + } + if(pthread_create(&ictx->tid, NULL, input_thread, ictx)){ + free_inputctx(ictx); + return -1; + } + // FIXME give ti a reference to ictx + loginfo("spun up input thread\n"); + return 0; +} + +int stop_inputlayer(tinfo* ti){ + // FIXME get ictx reference from ti, kill thread, free_inputctx() + return 0; +}