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 / WGETBT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-14  |  2.6 KB  |  87 lines

  1. /* wgetbt.c
  2. *
  3. * The Greenleaf Comm Library
  4. *
  5. * Copyright (C) 1989-90 Greenleaf Software Inc.  All Rights Reserved.
  6. *
  7. *  unsigned asiwgetb_timed( port, buffer, length, stat, 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. *  char *stat;          - Pointer to destination status buffer
  12. *  int ticks;           - The number of ticks to wait before timing out.
  13. *
  14. * DESCRIPTION
  15. *
  16. *  Transfers characters from receive queue to user buffer by repeatedly
  17. *  calling asiwgetc().  If the buffer is empty, the routine will wait
  18. *  around for some more characters until the tick timer runs out.
  19. *
  20. * SIDE EFFECTS
  21. *  none
  22. *
  23. * RETURNS
  24. *  returns the number of characters SUCCESSFULLY transferred.  The global
  25. *  variable _aserror can be examined to determine if an error was detected.
  26. *  _aserror == 0 if no errors were detected.  If the receive queue becomes
  27. *  empty before the entire user buffer is filled _aserror will be set to
  28. *  ASBUFREMPTY.
  29. *
  30. *       Value           Meaning
  31. *     -------          --------
  32. *       ASSUCCESS       port initialized (no error)
  33. *       ASINVPORT       Requested port is out of range
  34. *       ASNOTSETUP      Requested port not setup with asifirst()
  35. *       ASBUFREMPTY     Receive buffer went empty before length characters
  36. *                       were transferred.
  37. *       ASNOWIDERX      Wide Track receive not enabled for this channel.
  38. *
  39. * MODIFICATIONS
  40. *
  41. */
  42. #include <stdio.h>
  43. #include "gf.h"
  44. #include "asiports.h"
  45.  
  46. unsigned int GF_CONV asiwgetb_timed( int port,
  47.                              char *buffer,
  48.                              unsigned int length,
  49.                              char *stat,
  50.                              int ticks )
  51. {
  52.     unsigned rx_count = 0;
  53.     struct PORT_TABLE *p;
  54.  
  55.     p = _aschkcnl( port ) ;
  56.     if ( p == NULL )
  57.         return( 0 );
  58.  
  59.     if( p->chmode_bits.is_rxerror == 0 ) {
  60.         _aserror = ASNOWIDERX;
  61.         return(0);
  62.     }
  63.  
  64.     while ( length != 0 ) {
  65.         _aserror = asiwgetc( port, stat );
  66.         if ( _aserror >= 0 ) {
  67.             *buffer++ = ( char ) _aserror;
  68.             rx_count++;
  69.             length--;
  70.             if ( stat != NULL )
  71.                 stat++;
  72.         } else {
  73.             if ( _aserror == ASBUFREMPTY ) {
  74.                 if ( ticks <= 0)
  75.                     return( rx_count );
  76.                 ticks--;
  77.                 timer(1);
  78.             } else
  79.                 return( rx_count );
  80.         }
  81.     }
  82.  
  83.     _aserror=ASSUCCESS;
  84.     return(rx_count);
  85. }
  86.  
  87.