home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xnpipe.cpp < prev    next >
C/C++ Source or Header  |  1997-04-05  |  5KB  |  167 lines

  1. #include "XNPipe.h"
  2. #include "XcPipe.h"
  3.  
  4. /*@ 
  5. @class XNamedPipeServer
  6. @parent XIO
  7. @type overview
  8. @symbol _
  9. */
  10.  
  11.  
  12. /*@ 
  13. @class XNamedPipeClient
  14. @parent XIO
  15. @type overview
  16. @symbol _
  17. */
  18.  
  19.  
  20. /*@ XNamedPipeServer::GetState(void)
  21. @group misc
  22. @remarks Query the state of a pipeserver
  23. @returns <t '°' c=2>
  24. °LONG state   °possible values:
  25.                     <t '°' c=1>
  26.                         °XNPIPE_STATE_DISCONNECTED
  27.                         °XNPIPE_STATE_LISTENING
  28.                         °XNPIPE_STATE_CONNECTED
  29.                         °XNPIPE_STATE_CLOSING
  30.                     </t>
  31. </t>
  32. */
  33. LONG XNamedPipeServer::GetState(void)
  34. {
  35.     ULONG state, buffer, buffer2;
  36.     AVAILDATA avail;
  37.  
  38.     DosPeekNPipe(handle, &buffer, 4, &buffer2, &avail, &state);
  39.     return state;
  40. }
  41.  
  42.  
  43. LONG XNamedPipeClient::GetState(void)
  44. {
  45.     ULONG state, buffer, buffer2;
  46.     AVAILDATA avail;
  47.  
  48.     DosPeekNPipe(handle, &buffer, 4, &buffer2, &avail, &state);
  49.     return state;
  50. }
  51.  
  52.  
  53. /*@ XNamedPipeServer::Open(char *name, ULONG openMode, ULONG pipeMode, char pipeCount, LONG outSize, long inSize, ULONG timeOut)
  54. @group open/close
  55. @remarks Open a pipe, after you have opened it call Connect()
  56. @parameters <t '°' c=2>
  57.                 °char * name       °pipename, without leading '\\PIPE\\'
  58.             °ULONG openMode    °mode to open (see OS/2 docs):
  59.                                         <t '°' c=1>
  60.                                  °XNPIPE_ACCESS_INBOUND
  61.                                  °XNPIPE_ACCESS_OUTBOUND
  62.                                  °XNPIPE_ACCESS_DUPLEX
  63.                                  °XNPIPE_INHERIT
  64.                                  °XNPIPE_NOINHERIT
  65.                                  °XNPIPE_WRITEBEHIND
  66.                                  °XNPIPE_NOWRITEBEHIND
  67.                                         </t>
  68.             °ULONG pipeMode    °mode of data-transfer:
  69.                                         <t '°' c=1>
  70.                                  °XNPIPE_READMODE_BYTE
  71.                                  °XNPIPE_READMODE_MESSAGE
  72.                                  °XNPIPE_TYPE_BYTE
  73.                                  °XNPIPE_TYPE_MESSAGE
  74.                                  °XNPIPE_WAIT
  75.                                  °XNPIPE_NOWAIT
  76.                                         </t>
  77.             °char pipeCount    °maximum instances of pipe-servers, -1 = unlimited (default is 1)
  78.             °ULONG outSize     °size of write-buffer
  79.             °ULONG inSize      °size of read-buffer
  80.             °ULONG timeOut     °time to wait for clients
  81.             </t>
  82. */
  83. LONG XNamedPipeServer::Open(char *name, ULONG openMode, ULONG pipeMode, char pipeCount, LONG outSize, long inSize, ULONG timeOut)
  84. {
  85.    XString n = "\\PIPE\\";
  86.     n += name;
  87.     pipeMode |= pipeCount;
  88.     ULONG rc = DosCreateNPipe((PSZ) n, &handle, openMode, pipeMode, outSize, inSize, timeOut);
  89.  
  90.     if (rc == 0)
  91.         isOpen = TRUE;
  92.     return rc;
  93. }
  94.  
  95.  
  96. /*@ XNamedPipeServer::Connect(void)
  97. @group open/close
  98. @remarks Wait for a client
  99. */
  100. LONG XNamedPipeServer::Connect(void)
  101. {
  102.     return DosConnectNPipe(handle);
  103. }
  104.  
  105.  
  106. /*@ XNamedPipeServer::DisConnect(void)
  107. @group open/close
  108. @remarks Frees a pipe when a client has stoped data-transfer ( if GetState() returns XNPIPE_STATE_CLOSING).
  109. After DisConnect() you can call Connect() to wait for the next client or Close().
  110. */
  111. LONG XNamedPipeServer::DisConnect(void)
  112. {
  113.     ULONG res = 0;
  114.  
  115.     if (isOpen)
  116.         res = DosDisConnectNPipe(handle);
  117.     return res;
  118. }
  119.  
  120.  
  121. /*@ XNamedPipeClient::WaitForServer(char *name, ULONG timeOut)
  122. @group misc
  123. @remarks Wait for a server
  124. @parameters <t '°' c=2>
  125.                 °char * name    °name of the requested pipe (without leading '\\PIPE\\')
  126.                 °ULONG timeOut  °how long to wait
  127.                 °char * server     °name of the server-maschine if the pipe is not on the local maschine<BR>(default is NULL)
  128.                 </t>
  129. */
  130. LONG XNamedPipeClient::WaitForServer(char *name, ULONG timeOut, char * server)
  131. {
  132.     XString n;
  133.     if(server)
  134.     {
  135.         n += "\\";
  136.         n += server;
  137.     }
  138.     n += "\\PIPE\\";
  139.     n += name;    
  140.     return DosWaitNPipe((PSZ) n, timeOut);
  141. }
  142.  
  143.  
  144. /*@ XNamedPipeClient::Open(char *name, ULONG modeopen)
  145. @group open/close
  146. @remarks Opens a connection, after it is open call WaitForServer()
  147. @parameters <t '°' c=2>
  148.                 °char * name    °name of the requested pipe (without leading '\\PIPE\\'
  149.                 °ULONG modeOpen °mode to open (see XFile::Open() for possible modes
  150.                 °char * server    °name of the server-maschine if the pipe is not on the local maschine<BR>(default is NULL)
  151.                 </t>
  152. */
  153. LONG XNamedPipeClient::Open(char *name, ULONG modeopen, char * server)
  154. {
  155.     ULONG aktion;
  156.     XString n;
  157.     if(server)
  158.     {
  159.         n += "\\";
  160.         n += server;
  161.     }
  162.     n += "\\PIPE\\";
  163.     n += name;    
  164.     return DosOpen((PSZ) n, &handle, &aktion, 0, FILE_NORMAL, FILE_OPEN, modeopen, NULL);
  165. }
  166.  
  167.