in reply to Re: Umm... Win32::Pipe
in thread Umm... Win32::Pipe

I'm not the author, but I have the CPAN co-maintainer bit for the module and can publish fixes/updates. So feel free to file bugs / patches to the RT queue for Win32::Pipe.

I know Dave Roth had at one point an updated version on his own web site, but that version was no longer under the Artistic license, so I wouldn't want to apply those changes to the CPAN version.

The code is now hosted on Google Code

Replies are listed 'Best First'.
Re^3: Umm... Win32::Pipe
by BrowserUk (Patriarch) on Oct 08, 2008 at 02:15 UTC

    Frankly, I think it would be easier to start again. This time, ensuring that all the relevant APIs are exposed.

    If you look at the remarks section of ConnectNamedPipe, in particular, the first bit about the GetlastError returns and contrast them with the comment in the existing POD about waiting forever, I think you might begin to see what I mean.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      With some help of Win32::API and Win32API::File one can replace the hole Win32::Pipe module. The code below might help to put one on the right track. Server side:

      use strict; use Win32; use Win32::API; use Win32API::File qw( :Func ); use constant { PIPE_NAME => "//./pipe/X" , PIPE_ACCESS_INBOUND => 0x00000001 , FILE_FLAG_FIRST_PIPE_INSTANCE => 0x00080000 , PIPE_TYPE_MESSAGE => 0x00000004 , PIPE_READMODE_MESSAGE => 0x00000002 }; my $NULL = 0; # Note warning on LPSECURITY_ATTRIBUTES, but used only as NULL pointer Win32::API->Import('kernel32' ,'HANDLE CreateNamedPipe( LPCTSTR lpName ' . ', DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances' . ', DWORD nOutBufferSize, DWORD nInBufferSize' . ', DWORD nDefaultTimeOut' . ', LPSECURITY_ATTRIBUTES lpSecurityAttributes)' ); # Note warning on LPOVERLAPPED, but used only as NULL pointer. Win32::API->Import('kernel32' ,'BOOL ConnectNamedPipe(HANDLE hNamedPipe' . ', LPOVERLAPPED lpOverlapped )'); Win32::API->Import('kernel32' ,'BOOL DisconnectNamedPipe(HANDLE hNamedPipe)'); my $pipehandle = CreateNamedPipe( PIPE_NAME , PIPE_ACCESS_INBOUND + FILE_FLAG_FIRST_PIPE_INSTANCE , PIPE_TYPE_MESSAGE + PIPE_READMODE_MESSAGE , 1 , 512 , 512 , 10000 , $NULL ) or die "Unable to create pipe:". Win32::GetLastError() ; my( $res, $message); while( 1 ) { ConnectNamedPipe($pipehandle,$NULL) or die "Connect failed: ". Win32::GetLastError(); $res = ReadFile($pipehandle,$message, 512, [], [] ); print "$message\n"; $res = DisconnectNamedPipe($pipehandle); if( $message eq "exit" ) { last; } } $res = CloseHandle($pipehandle);
      Client side:
      use strict; use Win32; use Win32API::File qw( :Func :Misc :GENERIC_ ); use constant { PIPE_NAME => "//./pipe/X" }; my $pipehandle; while( ! $pipehandle ) { # Open client side of pipe. $pipehandle = CreateFile( PIPE_NAME, GENERIC_WRITE, 0, [] , OPEN_EXISTING , 0, [] ); if( ! $pipehandle ) { # Error during opening my $e = Win32::GetLastError(); my $m = Win32::FormatMessage($e); print "Error ($e):$m\n"; exit; } } #write the message and close my $res = WriteFile($pipehandle, $ARGV[0], length($ARGV[0]), [], [] ); my $res = CloseHandle($pipehandle);

      20081129 Janitored by Corion: Changed PRE to P tags, as per Writeup Formatting Tips