Win32::Pipe - Win32 Named Pipe
To use this extension, follow these basic steps. First, you need to 'use' the pipe extension:
Then you need to create a server side of a named pipe:
$Pipe = Win32::Pipe->new("My Pipe Name");
or if you are going to connect to pipe that has already been created:
$Pipe = Win32::Pipe->new("\\\\server\\pipe\\My Pipe Name"); NOTE: The "\\\\server\\pipe\\" is necessary when connecting to an existing pipe! If you are accessing the same machine you could use "\\\\.\\pipe\\" but either way works fine.
You should check to see if
$Pipe is indeed defined otherwise there has been an error.
Whichever end is the server, it must now wait for a connection...
$Result = $Pipe->Connect(); NOTE: The client end does not do this! When the client creates the pipe it has already connected!
Now you can read and write data from either end of the pipe:
$Data = $Pipe->Read(); $Result = $Pipe->Write("Howdy! This is cool!");
When the server is finished it must disconnect:
Now the server could
Connect again (and wait for another client) or it could destroy the named pipe...
The client should
Close in order to properly end the session.
This extension gives Win32 Perl the ability to use Named Pipes. Why? Well considering that Win32 Perl does not (yet) have the ability to
fork I could not see what good the
pipe(X,Y) was. Besides, where I am as an admin I must have several perl daemons running on several NT Servers. It dawned on me one day that if I could pipe all these daemons' output to my workstation (across the net) then it would be much easier to monitor. This was the impetus for an extension using Named Pipes. I think that it is kinda cool. :)
And what are the benefits of this module?
You may create as many named pipes as you want (uh, well, as many as your resources will allow).
Currently there is a limit of 256 instances of a named pipe (once a pipe is created you can have 256 client/server connections to that name).
The default buffer size is 512 bytes; this can be altered by the
All named pipes are byte streams. There is currently no way to alter a pipe to be message based.
Other things that I cannot think of right now... :)
Creates a named pipe if used in server context or a connection to the specified named pipe if used in client context. Client context is determined by prepending $Name with "\\\\".
Returns true on success, false on failure.
Returns the size of the instance of the buffer of the named pipe.
Tells the named pipe to create an instance of the named pipe and wait until a client connects. Returns true on success, false on failure.
Closes the named pipe.
Disconnects (and destroys) the instance of the named pipe from the client. Returns true on success, false on failure.
Returns the last error messages pertaining to the named pipe. If used in context to the package. Returns a list containing
Reads from the named pipe. Returns data read from the pipe on success, undef on failure.
Sets the size of the buffer of the instance of the named pipe to
SIZE. Returns the size of the buffer on success, false on failure.
DATA to the named pipe. Returns true on success, false on failure.
What known problems does this thing have?
If someone is waiting on a
Read and the other end terminates then you will wait for one REALLY long time! (If anyone has an idea on how I can detect the termination of the other end let me know!)
All pipes are blocking. I am considering using threads and callbacks into Perl to perform async IO but this may be too much for my time stress. ;)
There is no security placed on these pipes.
This module has neither been optimized for speed nor optimized for memory consumption. This may run into memory bloat.
If you wish to use this module with a build of Perl other than ActivePerl, you may wish to fetch the source distribution for this module. The source is included as part of the
libwin32 bundle, which you can find in any CPAN mirror here:
The source distribution also contains a pair of sample client/server test scripts. For the latest information on this module, consult the following web site:
Dave Roth <firstname.lastname@example.org>
I do not guarantee ANYTHING with this package. If you use it you are doing so AT YOUR OWN RISK! I may or may not support this depending on my time schedule.
Copyright (c) 1996 Dave Roth. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.