#ifndef GHOST_IO_H #define GHOST_IO_H // This version of Read sends 1 char at a time, it does not send blocks. // It would probably be better to split this functionalty? // Currently has no 'error' trigger link - but it should have, I suppose class Read { public: Link rtr; // ready toread Link eof; Link, Read> block; int fd; Read(int fd, trigger& rtr, trigger& eof, Block &block) : fd(fd), rtr(rtr, this, &Read::signal_rtr), eof(eof, this, &Read::signal_eof), error(error, this, &Read::signal_error), block(block, this, &Read::signal_block) {} void signal_rtr() { buf.size = read(fd, block.o.start, block.capacity); if (buf.size > 0) { block.signal(); } else if (buf.size == 0) { eof.signal(); } else if (nread < 0) { error.o = errno; error.signal(); } } void send_char() { c.o = *next; c.signal(); } void signal_c_ack() { assert(next >= buf && next < end); next++; if (next < end) { send_char(); } else { next = 0; ready_to_read.signal(); } } void signal_eof_ack() { assert(next == 0); //ready_to_read.signal(); // close the file? don't actually want to try to read it anymore } }; #endif