home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-1.ZIP / GCOMM / GETBT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-14  |  2.3 KB  |  73 lines

  1. /* getbt.c
  2. *
  3. * The Greenleaf Comm Library
  4. *
  5. * Copyright (C) 1985-1990 Greenleaf Software Inc.  All Rights Reserved.
  6. *
  7. *  unsigned asigetb( port, buffer, length, ticks)
  8. *  int port;            - Port 0..MAX_PORT-1
  9. *  char *buffer;        - Points to buffer that is to receive characters
  10. *  unsigned length;     - Maximum number of characters that can be received
  11. *  unsigned int ticks;  - The number of ticks to wait before returning
  12. *                         the ASBUFREMPTY code when no characters available.
  13. *
  14. * DESCRIPTION
  15. *
  16. *  Transfers characters from receive queue to user buffer by repeatedly
  17. *  calling asigetc().  Unlike asigetb(), this function will keep trying
  18. *  to fill the buffer even when it detects no characters available.
  19. *  It will keep trying to read characters in until it times out.
  20. *
  21. * SIDE EFFECTS
  22. *  none
  23. *
  24. * RETURNS
  25. *  returns the number of characters SUCCESSFULLY transferred.  The global
  26. *  variable _aserror can be examined to determine if an error was detected.
  27. *  _aserror == 0 if no errors were detected.  If the receive queue becomes
  28. *  empty before the entire user buffer is filled _aserror will be set to
  29. *  ASBUFREMPTY.
  30. *
  31. *       Value           Meaning
  32. *     -------          --------
  33. *       ASSUCCESS       port initialized (no error)
  34. *       ASINVPORT       Requested port is out of range
  35. *       ASNOTSETUP      Requested port not setup with asifirst()
  36. *       ASBUFREMPTY     Receive buffer went empty before length characters
  37. *                       were transferred.
  38. *
  39. * MODIFICATIONS
  40. */
  41. #include <stdio.h>
  42. #include "gf.h"
  43. #include "asiports.h"
  44.  
  45. unsigned GF_CONV asigetb_timed( int port,
  46.                         char *buffer,
  47.                         unsigned int length,
  48.                         int ticks)
  49. {
  50.     unsigned int rx_count;
  51.  
  52.     rx_count = 0;
  53.  
  54.     while ( length != 0 ) {
  55.         _aserror = asigetc( port );
  56.         if ( _aserror >= 0 ) {
  57.             *buffer++ = ( char ) _aserror;
  58.             rx_count++;
  59.             length--;
  60.         } else {
  61.             if ( _aserror == ASBUFREMPTY ) {
  62.                 if ( ticks <= 0 )
  63.                     return( rx_count );
  64.                 ticks--;
  65.                 timer(1);
  66.             } else
  67.                 return( rx_count );
  68.         }
  69.     }
  70.     _aserror = ASSUCCESS;
  71.     return( rx_count );
  72. }
  73.