home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / wizards / 3825 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  3.5 KB

  1. Path: sparky!uunet!olivea!spool.mu.edu!agate!dog.ee.lbl.gov!hellgate.utah.edu!fcom.cc.utah.edu!cs.weber.edu!terry
  2. From: terry@cs.weber.edu (A Wizard of Earth C)
  3. Newsgroups: comp.unix.wizards
  4. Subject: Re: Async IO problem
  5. Message-ID: <1992Sep7.085801.12524@fcom.cc.utah.edu>
  6. Date: 7 Sep 92 08:58:01 GMT
  7. References: <1992Sep5.113616.18458@cucs5.cs.cuhk.hk>
  8. Sender: news@fcom.cc.utah.edu
  9. Organization: Weber State University  (Ogden, UT)
  10. Lines: 66
  11.  
  12. In article <1992Sep5.113616.18458@cucs5.cs.cuhk.hk> wmchung@eng.ie.cuhk.hk (chung wai man) writes:
  13. >Hi!
  14. >
  15. >I have some problem about Async IO. In the Unix Network Programming
  16. >by Stevens, on P.327, it has an example program telling how to make
  17. >async IO. It has the codes:
  18. >
  19. >    sigblock(sigmask((SIGIO));
  20. >    while(sigflag == 0)
  21. >      sigpause(0);eee(0)
  22. >    
  23. >I wonder if these codes are necessary for Async IO. These codes seems that
  24. >the program will halt and wait for a signal. If it is so, it is just a
  25. >blocking socket waiting for something to receive.
  26. >
  27. >My concept for Async IO is that it is like a software interrupt. The 
  28. >program can go along. When something has received, it will be interrupted
  29. >, doing a routine already registered for signal SIGIO, then
  30. >resuming.
  31.  
  32. Sorry, but it isn't an interrupt.  It's a persistant condition.  You are
  33. not guaranteed a 1:1 correspodance between SIGIO signals handled by your
  34. handler and the conditions which cause the SIGIO signals to be sent to
  35. your process.  This is beacuse signal delivery is blocked in the handler
  36. and only 1 signal thereafter is marked until handler exit.
  37.  
  38. The code in the Steven's book shows the use of async I/O to multiplex
  39. input sources that generate SIGIO without buzz-looping.  This is because
  40. you check all possible sources after the wakeup.  That way if multiple
  41. channels have data simultaneously, you either handle it as a result of
  42. falling through sigpause(), or when you loop back up you fall through
  43. and handle it anyway (if a secong SIGIO occurs after that particular
  44. I/O source has been checked for the condition causing the SIGIO but before
  45. restarting the sigpause().)
  46.  
  47. Signals are not events, and signal handlers therefore can not be event
  48. handlers.  Period.  If you try to use them that way, the code will be
  49. unreliable in the multiple-signals-during-handler case.  Period.
  50.  
  51. A better mechanism for async I/O, if you are using SunOS or AIX, is to
  52. use the async I/O routines.  In the Sun implementation, this requires
  53. that you enable the ASYNCIO kernel option, and that the driver for the
  54. input source in question support the async flag.
  55.  
  56. I you absolutely *must* use multiple input sources, and either are not on
  57. AIX/SunOS, or your device driver is bad, try poll() and select().  Failing
  58. this, you can set up one child listener process per input source and write
  59. a common pipe back to the parent.
  60.  
  61. If you wait to write your program until your vendor adopts POSIX 1003.4,
  62. implements it, and ships you a copy, then you can have reliable signal
  63. delivery and queued multiple instances of a particular signal, thus
  64. guaranteeing a 1:1 relationship.
  65.  
  66.  
  67.                     Terry Lambert
  68.                     terry_lambert@gateway.novell.com
  69.                     terry@icarus.weber.edu
  70. ---
  71. Any opinions in this posting are my own and not those of my present
  72. or previous employers.
  73. -- 
  74. -------------------------------------------------------------------------------
  75.                                                        terry@icarus.weber.edu
  76.  "I have an 8 user poetic license" - me
  77. -------------------------------------------------------------------------------
  78.