home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / __fselect.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  3.0 KB  |  115 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.1
  10. date    92.05.14.19.55.40;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @lowlevel select function for plain files
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*
  26.  *  This file is part of ixemul.library for the Amiga.
  27.  *  Copyright (C) 1991, 1992  Markus M. Wild
  28.  *
  29.  *  This library is free software; you can redistribute it and/or
  30.  *  modify it under the terms of the GNU Library General Public
  31.  *  License as published by the Free Software Foundation; either
  32.  *  version 2 of the License, or (at your option) any later version.
  33.  *
  34.  *  This library is distributed in the hope that it will be useful,
  35.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  36.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  37.  *  Library General Public License for more details.
  38.  *
  39.  *  You should have received a copy of the GNU Library General Public
  40.  *  License along with this library; if not, write to the Free
  41.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  42.  *
  43.  *  $Id$
  44.  *
  45.  *  $Log$
  46.  */
  47.  
  48. #define KERNEL
  49. #include "ixemul.h"
  50.  
  51. #include "select.h"
  52.  
  53. /* don't use the `normal' packet port for select. We need synchronous
  54.  * notification to be able to Wait() for multiple replies */
  55. #undef __rwport
  56. #define __rwport (u.u_sync_mp)
  57.  
  58. #ifdef DEBUG
  59. #define DP(a) kprintf a
  60. #else
  61. #define DP(a)
  62. #endif
  63.  
  64. /*
  65.  * select operation on a "normal" AmigaDOS filehandle. Normal means,
  66.  * we only have the WaitForChar() call available to find out, whether
  67.  * a read would block. Write() cannot be caught, so we always allow it.
  68.  * Request for exceptional data is routed to read.
  69.  */
  70.  
  71. int
  72. __fselect (struct file *f, int select_cmd, int io_mode)
  73. {
  74.   int result;
  75.  
  76.   if (select_cmd == SELCMD_PREPARE)
  77.     {
  78.       /* always possible... perhaps return ~0 in this case ???? */
  79.       if (io_mode != SELMODE_IN) return 0;
  80.  
  81.       /* should not wait here, but I have to.. the only case that a packet
  82.        * could be outstanding, is if this is a file open for read and write,
  83.        * and an async write is outstanding. Since I'm testing for read I have
  84.        * to wait for write() to complete */
  85.       __get_file (f);
  86.       __wait_packet (&f->f_sp);
  87.       LastError(f) = 0;
  88.  
  89.       /* convert usec into ticks.. */
  90.       SendPacket1(f,__rwport,ACTION_WAIT_CHAR,SELTIMEOUT * TICKS_PER_SECOND / 1000000);
  91.       return 1 << __rwport->mp_SigBit;
  92.     }
  93.   else if (select_cmd == SELCMD_CHECK)
  94.     {
  95.       /* only read is supported, other modes default to `ok' */
  96.       if (io_mode != SELMODE_IN) return 1;
  97.  
  98.       __wait_sync_packet (&f->f_sp);
  99.       /* there are two possible answers: error (packet not supported) 
  100.        * and the `real' answer.
  101.        * An error is treated as to allow input, so select() won't block
  102.        * indefinitely...
  103.        * & 1 converts dos-true (-1) into normal true (1) ;-)
  104.        */
  105.       result = LastError(f) ? 1 : (LastResult(f) & 1);
  106.       /* don't make __write() think its last packet failed.. */
  107.       LastError(f) = 0;
  108.       __release_file (f);
  109.       return result;
  110.     }
  111.   else
  112.     return 0;
  113. }
  114. @
  115.