home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / MISC / mtp.shar / mtpcommon.c < prev    next >
C/C++ Source or Header  |  2009-11-06  |  2KB  |  81 lines

  1. /* mtpcommon.c, Version 1.1, Created 2/9/90 */
  2. /* Dr Alan M. McIvor, BP Sunbury Research Centre */
  3.  
  4. #include <stdio.h>
  5. #include "mtp.h"
  6.  
  7. /* These first two functions are for block I/O. Flooding the buffer
  8.    such as with 
  9.  
  10.   for (i = os9modhead._msize, ptr = module; i > 0; i-=j, ptr+=j)
  11.     if ((j = write(s, ptr, i)) == -1)
  12.       {
  13.     fprintf(stderr, "put_module: Error on socket I/O\n");
  14.     return(-1);
  15.       }
  16.  
  17.   memory = module_memory;
  18.   j = 0;
  19.   i = module_size;
  20.   while (i > 0)
  21.     {
  22.       if ((j = read(ns, memory, i)) == -1)
  23.     shutdown_exit(ns, _errmsg(errno, "Error on socket I/O - "));
  24.       i -= j;
  25.       memory += j;
  26.     }
  27.  
  28.   seems to upset the OS-9 system. Sometimes the module ends up with an
  29.   invalid CRC, which can only happen if at least one byte is screwed up
  30.   which should be impossible. Sometimes the OS-9 system crashes and won't
  31.   reboot properly unless it is powered down - something in the Ethernet
  32.   control registers must get screwed up.
  33.  
  34. */
  35.  
  36.  
  37. /* Assume the block size is always read */
  38.  
  39. int read_block(s, pbuf, bsize)
  40.      int s;            /* socket descriptor */
  41.      char *pbuf;        /* ptr to data buffer */
  42.      int bsize;            /* data size in bytes */
  43. {
  44.   /* read data from socket, return bsize if no error, -1 if error */
  45.   int no_to_read;
  46.   int no_read;
  47.  
  48.   no_to_read = bsize;
  49.   while (no_to_read > 0)
  50.     {
  51.       if ((no_read = read(s, pbuf, no_to_read)) == -1)
  52.     return(-1);
  53.       pbuf += no_read;
  54.       no_to_read -= no_read;
  55.     }
  56.  
  57.   return(bsize);
  58. }
  59.   
  60.  
  61. int write_block(s, pbuf, bsize)
  62.      int s;            /* socket descriptor */
  63.      char *pbuf;        /* ptr to data buffer */
  64.      int bsize;            /* data size in bytes */
  65. {
  66.   /* write data into socket, return bsize if no error, -1 if error */
  67.   int no_to_write;
  68.   int no_written;
  69.  
  70.   no_to_write = bsize;
  71.   while (no_to_write > 0)
  72.     {
  73.       if ((no_written = write(s, pbuf, no_to_write)) == -1)
  74.     return(-1);
  75.       pbuf += no_written;
  76.       no_to_write -= no_written;
  77.     }
  78.  
  79.   return(bsize);
  80. }
  81.