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 >
Wrap
C/C++ Source or Header
|
1997-08-21
|
5KB
|
172 lines
#include "XNPipe.h"
#include "XcPipe.h"
/*@
@class XNamedPipeServer
@parent XIO
@type overview
@symbol _
*/
/*@
@class XNamedPipeClient
@parent XIO
@type overview
@symbol _
*/
/*@ XNamedPipeServer::GetState(void)
@group misc
@remarks Query the state of a pipeserver
@returns <t '°' c=2>
°LONG state °possible values:
<t '°' c=1>
°XNPIPE_STATE_DISCONNECTED
°XNPIPE_STATE_LISTENING
°XNPIPE_STATE_CONNECTED
°XNPIPE_STATE_CLOSING
</t>
</t>
*/
LONG XNamedPipeServer::GetState(void)
{
ULONG state, buffer, buffer2;
AVAILDATA avail;
DosPeekNPipe(handle, &buffer, 4, &buffer2, &avail, &state);
return state;
}
LONG XNamedPipeClient::GetState(void)
{
ULONG state, buffer, buffer2;
AVAILDATA avail;
DosPeekNPipe(handle, &buffer, 4, &buffer2, &avail, &state);
return state;
}
/*@ XNamedPipeServer::Open(char *name, ULONG openMode, ULONG pipeMode, char pipeCount, LONG outSize, long inSize, ULONG timeOut)
@group open/close
@remarks Open a pipe, after you have opened it call Connect()
@parameters <t '°' c=2>
°char * name °pipename, without leading '\\PIPE\\'
°ULONG openMode °mode to open (see OS/2 docs):
<t '°' c=1>
°XNPIPE_ACCESS_INBOUND
°XNPIPE_ACCESS_OUTBOUND
°XNPIPE_ACCESS_DUPLEX
°XNPIPE_INHERIT
°XNPIPE_NOINHERIT
°XNPIPE_WRITEBEHIND
°XNPIPE_NOWRITEBEHIND
</t>
°ULONG pipeMode °mode of data-transfer:
<t '°' c=1>
°XNPIPE_READMODE_BYTE
°XNPIPE_READMODE_MESSAGE
°XNPIPE_TYPE_BYTE
°XNPIPE_TYPE_MESSAGE
°XNPIPE_WAIT
°XNPIPE_NOWAIT
</t>
°char pipeCount °maximum instances of pipe-servers, -1 = unlimited (default is 1)
°ULONG outSize °size of write-buffer
°ULONG inSize °size of read-buffer
°ULONG timeOut °time to wait for clients
</t>
*/
LONG XNamedPipeServer::Open(char *name, ULONG openMode, ULONG pipeMode, char pipeCount, LONG outSize, long inSize, ULONG timeOut)
{
XString n = "\\PIPE\\";
n += name;
pipeMode |= pipeCount;
ULONG rc = DosCreateNPipe((PSZ) (char*) n, &handle, openMode, pipeMode, outSize, inSize, timeOut);
if (rc == 0)
isOpen = TRUE;
else
handle = -1;
return rc;
}
/*@ XNamedPipeServer::Connect(void)
@group open/close
@remarks Wait for a client
*/
LONG XNamedPipeServer::Connect(void)
{
return DosConnectNPipe(handle);
}
/*@ XNamedPipeServer::DisConnect(void)
@group open/close
@remarks Frees a pipe when a client has stoped data-transfer ( if GetState() returns XNPIPE_STATE_CLOSING).
After DisConnect() you can call Connect() to wait for the next client or Close().
*/
LONG XNamedPipeServer::DisConnect(void)
{
ULONG res = 0;
if (isOpen)
res = DosDisConnectNPipe(handle);
return res;
}
/*@ XNamedPipeClient::WaitForServer(char *name, ULONG timeOut)
@group misc
@remarks Wait for a server
@parameters <t '°' c=2>
°char * name °name of the requested pipe (without leading '\\PIPE\\')
°ULONG timeOut °how long to wait
°char * server °name of the server-maschine if the pipe is not on the local maschine<BR>(default is NULL)
</t>
*/
LONG XNamedPipeClient::WaitForServer(char *name, ULONG timeOut, char * server)
{
XString n;
if(server)
{
n += "\\";
n += server;
}
n += "\\PIPE\\";
n += name;
return DosWaitNPipe((PSZ) (char*) n, timeOut);
}
/*@ XNamedPipeClient::Open(char *name, ULONG modeopen)
@group open/close
@remarks Opens a connection, after it is open call WaitForServer()
@parameters <t '°' c=2>
°char * name °name of the requested pipe (without leading '\\PIPE\\'
°ULONG modeOpen °mode to open (see XFile::Open() for possible modes
°char * server °name of the server-maschine if the pipe is not on the local maschine<BR>(default is NULL)
</t>
*/
LONG XNamedPipeClient::Open(char *name, ULONG modeopen, char * server)
{
ULONG aktion;
XString n;
if(server)
{
n += "\\";
n += server;
}
n += "\\PIPE\\";
n += name;
ULONG rc = DosOpen((PSZ) (char*) n, &handle, &aktion, 0, FILE_NORMAL, FILE_OPEN, modeopen, NULL);
if( rc )
handle = -1;
return rc;
}