home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / os2 / programm / 4446 < prev    next >
Encoding:
Internet Message Format  |  1992-08-25  |  2.5 KB

  1. Path: sparky!uunet!vnet.ibm.com
  2. From: peterf@vnet.ibm.com (Peter Forsberg)
  3. Message-ID: <19920826.040756.330@almaden.ibm.com>
  4. Date: Wed, 26 Aug 92 12:48:36 SWE
  5. Newsgroups: comp.os.os2.programmer
  6. Subject: Re: DosReadQueue and Timeouts
  7. Reply-To: peterf@vnet.ibm.com
  8. Organization: IBM Corporation
  9. Disclaimer: This posting represents the poster's views, not those of IBM
  10. News-Software: UReply 3.0
  11. References: <meek.714371000@fizzy>
  12. Lines: 51
  13.  
  14. In <meek.714371000@fizzy> Lindsay Meek writes:
  15. >Hello OS/2 people,
  16. >   I'm trying to write a queue handler that incorperates the timeout
  17. >feature available with semaphores i.e. DosSemWait(semaphore,timeout(ms))
  18. >   I'm habving trouble getting DosReadQueue to suspend for a finite
  19. >duration . Im using DosStartTimer and DosStopTimer and supplying the same
  20. >semaphore as that used by the DosReadQueue function (in the hope that
  21. >the Timer will signal on behalf of the DosReadQueue function). But it ain't
  22. >working..
  23. >   Has anybody had experience with this, or can suggest a method for
  24. >doing it using the API calls?
  25. >
  26. >Thanks
  27. >   Lindsay Meek (meek@fizzy.csu.murdoch.edu.au)
  28. >
  29.  
  30. Lindsay,
  31.  
  32. I'm doing exactly the same thing that you want to do in the following way
  33. (without using a timer):
  34.  
  35. 1. Create a semaphore (I use a RAM semaphore), and SET it.
  36.  
  37. 2. Create the queue.
  38.  
  39. 3. Do an initial read on the queue, with the NoWait argument = (CHAR)1,
  40.    and supply the semaphore handle of your semaphore.
  41.    Try to do this while the queue is empty. You will then get the return-
  42.    code ERROR_QUE_EMPTY - your semaphore is now registered by the queue
  43.    subsystem, and will be CLEARed when something arrives in your queue.
  44.  
  45. 4. You can now do a DosSemWait on your semaphore, and use the timeout
  46.    value as you like.
  47.  
  48. 5. If you get NO_ERROR from DosSemWait, you have element(s) in the queue.
  49.    SET the semaphore.  Read elements with the same NoWait and semaphore
  50.    arguments as in 3.  The semaphore will not be registered again until
  51.    you get ERROR_QUE_EMPTY from DosReadQueue.  You can now GOTO 4, and
  52.    wait on the semaphore again.
  53.  
  54.    If you get ERROR_SEM_TIMEOUT from DosSemWait you can do your house-
  55.    keeping (or whatever). The semaphore will stay SET and registered in
  56.    the queue subsystem, so you just have to go back to 4 when you're done.
  57.  
  58. Hope this helps  (if not I can send you a code fragment)
  59.  
  60. Peter
  61. --
  62. Peter Forsberg           E-mail:  peterf@vnet.ibm.com          (primary)
  63.                                   d88-pfo@nada.kth.se        (alternate)
  64. Disclaimer: This posting represents the poster's views, not those of IBM
  65.