home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / queue1.zip / OS2QUE.DOC < prev    next >
Text File  |  1988-10-10  |  3KB  |  62 lines

  1. These files have been uploaded in response to message #36711 from Steve
  2. Liberty 71450,2341.  Since these are questions of a general interest, the
  3. response has been posted here.
  4.  
  5. An example program is attached (files CLIENT.C and SERVER.C) that demonstrates
  6. some of the concepts that are outlined in the answers to the following
  7. questions about using queue's in OS/2.
  8.  
  9. For the sake of convenience, the contents of Steve's original question have
  10. been included here.
  11.  
  12. >#: 36711 S8/OS/2
  13. >    07-Oct-88  09:55:28
  14. >Sb: Queue questions
  15. >Fm: STEVE LIBERTY 71450,2341
  16. >To: all
  17. >
  18. >I am playing around with Queues, and have several questions. If anyone can
  19. >help me clear up my hazy understanding on this topic, I would greatly
  20. >appreciate it.
  21. >
  22. >First, am I correct that the data being passed from one process to another
  23. >must be passed in shared memory? It appears from the docs that the only data
  24. >that can actually be contained in the queue packet is an unsigned event_code.
  25. >So I assume that the data address field of the packet points into some shared
  26. >memory. Is that right?
  27.  
  28. ** Right; queues only pass the address of the data back and forth. It is
  29. the responsibility of the process to set up a data transfer area- usually
  30. a piece of shared memory.
  31.  
  32. >Next, if that is correct, what is the best way to handle the shared memory?
  33. >Does it matter whether the reader or writer allocates the memory? Should it
  34. >selector be accessed by the other via a DosGetShrSeg call?
  35.  
  36. ** There are no hard and fast rules for this but the attached example uses
  37. the method that you describe, namely that the client process opens the
  38. shared segment and the server opens this segment using DosGetShrSeg.
  39.  
  40. >Finally, if all of the above is somewhat on track, once the selector is found
  41. >say by the writer, how does he move a string into the shared memory? For
  42. >example can he simply use strcpy? How is the selector converted into an
  43. >address, and can that address be incremented by the string's length to get to
  44. >the next slot?
  45.  
  46. ** The best way to handle the allocation is to use DosSubAlloc to allocate
  47. space for each object from within the client process and then have the
  48. server process free this block when it is done reading the information.
  49. Doing it this way insures that you will not have any data corruption and
  50. freeing the memory after its use will return the memory to the pool for
  51. subsequent writes (i.e. allocations) by the client process. As for the
  52. actual transfer of information from the client to the shared segment,
  53. memcpy or strcpy work fine for this. The attached example use strcpy
  54. because the information transfered is a string.
  55.  
  56. Here is how to use the attached example: Compile CLIENT.C and SERVER.C
  57. seperatly with /AL (large model). Detach CLIENT.EXE and then run SERVER.EXE.
  58. Alternately, you can run CLIENT.EXE in one screen group, switch to another
  59. and run SERVER.EXE.
  60.  
  61. If you have any other questions or problems, let us know.
  62.