Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. int io_read(resmgr_context_t *ctp, io_read_t *msg, Coreocb_t *cocb) {
  2.     int nb;
  3.     int fd;
  4.     char * buf;
  5.         buf = (char *) (msg + 1);
  6.  
  7.     switch (cocb->ocb.attr->device) {
  8.             case WPUMP:
  9.                 fd = open("waterpump.txt", O_RDONLY);
  10.                 break;
  11.             case WLEVEL:
  12.                 printf("We got here\n");
  13.                 fd = open("waterLevel.txt", O_RDONLY );
  14.                 break;
  15.             case CTEMP:
  16.                 fd = open("coretemp.txt", O_RDONLY );
  17.                 break;
  18.             case CRODS:
  19.                 fd = open("controds.txt", O_RDONLY );
  20.                 break;
  21.             }
  22.  
  23.     nb = read(fd, buf,msg->i.nbytes);
  24.     if (cocb->ocb.offset == nb)
  25.             return 0;
  26.  
  27.         //We will return which ever is smaller the size of our data or the size of the buffer
  28.         nb = min(nb, msg->i.nbytes);
  29.  
  30.         //Set the number of bytes we will return
  31.         _IO_SET_READ_NBYTES(ctp, nb);
  32.  
  33.         //Copy data into reply buffer.
  34.         SETIOV(ctp->iov, buf, nb);
  35.  
  36.         //update offset into our data used to determine start position for next read.
  37.         cocb->ocb.offset += nb;
  38.  
  39.         //If we are going to send any bytes update the access time for this resource.
  40.         if (nb > 0)
  41.             cocb->ocb.attr->attr.flags |= IOFUNC_ATTR_ATIME;
  42.  
  43.         return (_RESMGR_NPARTS(1));
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement