Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int io_read(resmgr_context_t *ctp, io_read_t *msg, Coreocb_t *cocb) {
- int nb;
- int fd;
- char * buf;
- buf = (char *) (msg + 1);
- switch (cocb->ocb.attr->device) {
- case WPUMP:
- fd = open("waterpump.txt", O_RDONLY);
- break;
- case WLEVEL:
- printf("We got here\n");
- fd = open("waterLevel.txt", O_RDONLY );
- break;
- case CTEMP:
- fd = open("coretemp.txt", O_RDONLY );
- break;
- case CRODS:
- fd = open("controds.txt", O_RDONLY );
- break;
- }
- nb = read(fd, buf,msg->i.nbytes);
- if (cocb->ocb.offset == nb)
- return 0;
- //We will return which ever is smaller the size of our data or the size of the buffer
- nb = min(nb, msg->i.nbytes);
- //Set the number of bytes we will return
- _IO_SET_READ_NBYTES(ctp, nb);
- //Copy data into reply buffer.
- SETIOV(ctp->iov, buf, nb);
- //update offset into our data used to determine start position for next read.
- cocb->ocb.offset += nb;
- //If we are going to send any bytes update the access time for this resource.
- if (nb > 0)
- cocb->ocb.attr->attr.flags |= IOFUNC_ATTR_ATIME;
- return (_RESMGR_NPARTS(1));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement