home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / xnpipe.cpp < prev    next >
C/C++ Source or Header  |  1997-08-21  |  5KB  |  172 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) (char*) n, &handle, openMode, pipeMode, outSize, inSize, timeOut);
  89.  
  90.     if (rc == 0)
  91.         isOpen = TRUE;
  92.    else
  93.       handle = -1;
  94.     return rc;
  95. }
  96.  
  97.  
  98. /*@ XNamedPipeServer::Connect(void)
  99. @group open/close
  100. @remarks Wait for a client
  101. */
  102. LONG XNamedPipeServer::Connect(void)
  103. {
  104.     return DosConnectNPipe(handle);
  105. }
  106.  
  107.  
  108. /*@ XNamedPipeServer::DisConnect(void)
  109. @group open/close
  110. @remarks Frees a pipe when a client has stoped data-transfer ( if GetState() returns XNPIPE_STATE_CLOSING).
  111. After DisConnect() you can call Connect() to wait for the next client or Close().
  112. */
  113. LONG XNamedPipeServer::DisConnect(void)
  114. {
  115.     ULONG res = 0;
  116.  
  117.     if (isOpen)
  118.         res = DosDisConnectNPipe(handle);
  119.     return res;
  120. }
  121.  
  122.  
  123. /*@ XNamedPipeClient::WaitForServer(char *name, ULONG timeOut)
  124. @group misc
  125. @remarks Wait for a server
  126. @parameters <t '°' c=2>
  127.                 °char * name    °name of the requested pipe (without leading '\\PIPE\\')
  128.                 °ULONG timeOut  °how long to wait
  129.                 °char * server     °name of the server-maschine if the pipe is not on the local maschine<BR>(default is NULL)
  130.                 </t>
  131. */
  132. LONG XNamedPipeClient::WaitForServer(char *name, ULONG timeOut, char * server)
  133. {
  134.     XString n;
  135.     if(server)
  136.     {
  137.         n += "\\";
  138.         n += server;
  139.     }
  140.     n += "\\PIPE\\";
  141.     n += name;    
  142.     return DosWaitNPipe((PSZ) (char*) n, timeOut);
  143. }
  144.  
  145.  
  146. /*@ XNamedPipeClient::Open(char *name, ULONG modeopen)
  147. @group open/close
  148. @remarks Opens a connection, after it is open call WaitForServer()
  149. @parameters <t '°' c=2>
  150.                 °char * name    °name of the requested pipe (without leading '\\PIPE\\'
  151.                 °ULONG modeOpen °mode to open (see XFile::Open() for possible modes
  152.                 °char * server    °name of the server-maschine if the pipe is not on the local maschine<BR>(default is NULL)
  153.                 </t>
  154. */
  155. LONG XNamedPipeClient::Open(char *name, ULONG modeopen, char * server)
  156. {
  157.     ULONG aktion;
  158.     XString n;
  159.     if(server)
  160.     {
  161.         n += "\\";
  162.         n += server;
  163.     }
  164.     n += "\\PIPE\\";
  165.     n += name;    
  166.     ULONG rc = DosOpen((PSZ) (char*) n, &handle, &aktion, 0, FILE_NORMAL, FILE_OPEN, modeopen, NULL);
  167.    if( rc )
  168.       handle = -1;
  169.    return rc;
  170. }
  171.  
  172.