home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / microcode / os2pipe.c < prev    next >
C/C++ Source or Header  |  1999-01-02  |  3KB  |  94 lines

  1. /* -*-C-*-
  2.  
  3. $Id: os2pipe.c,v 1.8 1999/01/02 06:11:34 cph Exp $
  4.  
  5. Copyright (c) 1994-1999 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #include "os2.h"
  23.  
  24. static msg_t * input_pipe_reader (LHANDLE, qid_t, msg_t *, int *);
  25. static void input_pipe_operator
  26.   (Tchannel, chop_t, choparg_t, choparg_t, choparg_t);
  27.  
  28. void
  29. OS_make_pipe (Tchannel * readerp, Tchannel * writerp)
  30. {
  31.   HFILE hread;
  32.   HFILE hwrite;
  33.   STD_API_CALL (dos_create_pipe, ((&hread), (&hwrite), 4096));
  34.   transaction_begin ();
  35.   OS2_handle_close_on_abort (hwrite);
  36.   (*readerp) = (OS2_make_channel (hread, CHANNEL_READ));
  37.   transaction_commit ();
  38.   transaction_begin ();
  39.   OS_channel_close_on_abort (*readerp);
  40.   (*writerp) = (OS2_make_channel (hwrite, CHANNEL_WRITE));
  41.   transaction_commit ();
  42. }
  43.  
  44. void
  45. OS2_initialize_pipe_channel (Tchannel channel)
  46. {
  47.   if (CHANNEL_INPUTP (channel))
  48.     OS2_start_channel_thread (channel,
  49.                   input_pipe_reader,
  50.                   input_pipe_operator);
  51. }
  52.  
  53. static msg_t *
  54. input_pipe_reader (LHANDLE handle, qid_t qid, msg_t * message, int * eofp)
  55. {
  56.   ULONG nread;
  57.   APIRET rc
  58.     = (dos_read (handle,
  59.          (SM_READAHEAD_DATA (message)),
  60.          (sizeof (SM_READAHEAD_DATA (message))),
  61.          (& nread)));
  62.   if (rc == NO_ERROR)
  63.     {
  64.       (SM_READAHEAD_SIZE (message)) = nread;
  65.       (*eofp) = (nread == 0);
  66.       return (message);
  67.     }
  68.   OS2_destroy_message (message);
  69.   if (rc == ERROR_INVALID_HANDLE)
  70.     /* Handle was closed on us -- no need to do anything else.  */
  71.     return (0);
  72.   (*eofp) = (rc == ERROR_BROKEN_PIPE);
  73.   return (OS2_make_syscall_error (rc, syscall_dos_read));
  74. }
  75.  
  76. static void
  77. input_pipe_operator (Tchannel channel, chop_t operation,
  78.              choparg_t arg1, choparg_t arg2, choparg_t arg3)
  79. {
  80.   switch (operation)
  81.     {
  82.     case chop_read:
  83.       OS2_channel_thread_read_op (channel, arg1, arg2, arg3);
  84.       break;
  85.     case chop_close:
  86.       OS2_channel_thread_close (channel);
  87.       STD_API_CALL (dos_close, (CHANNEL_HANDLE (channel)));
  88.       break;
  89.     default:
  90.       OS2_logic_error ("Unknown operation for input pipe.");
  91.       break;
  92.     }
  93. }
  94.