in reply to Re^7: ... (Proof!)
in thread Non-blocking Reads from Pipe Filehandle
My original code, the one with the problem, was
Win32::API->Import( 'kernel32', 'BOOL PeekNamedPipe( HANDLE hNamedPipe, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesRead, LPDWORD lpTotalBytesAvail, LPDWORD lpBytesLeftThisMessage )', );
There's no way to pass NULL when using that syntax. Using that syntax is what sets has_proto. I may not have found the optimal *workaround*, but that doesn't mean the bug isn't there. I didn't use LPLPPP because I assumed it was buggy too.
More depression when I see people proffering this kind unnecessary complexity:
If you think LPLPPP is shorter...
BEGIN { # BOOL WINAPI PeekNamedPipe( # __in HANDLE hNamedPipe, # __out_opt LPVOID lpBuffer, # __in DWORD nBufferSize, # __out_opt LPDWORD lpBytesRead, # __out_opt LPDWORD lpTotalBytesAvail, # __out_opt LPDWORD lpBytesLeftThisMessage # ) my $f = Win32::API->new('kernel32', 'PeekNamedPipe', 'LPLPPP', 'L') or die $^E; sub PeekNamedPipe { my $vBuffer = defined($_[1]) ? $vBuffer : 0; my $nBytesRead = defined($_[3]) ? pack('L!', $_[3]) : 0; my $nTotalBytesAvail = defined($_[4]) ? pack('L!', $_[4]) : 0; my $nBytesLeftThisMsg = defined($_[5]) ? pack('L!', $_[5]) : 0; my $rv = $f->Call( $_[0], $vBuffer, $_[2], $nBytesRead, $nTotalBytesAvail, $nBytesLeftThisMsg, ); $_[1] = $vBuffer if defined $_[1]; $_[3] = unpack('L!', $nBytesRead ) if defined $_[3]; $_[4] = unpack('L!', $nTotalBytesAvail ) if defined $_[4]; $_[5] = unpack('L!', $nBytesLeftThisMsg) if defined $_[5]; return $rv; } }
That's why I prefer to use the prototype approach. It's much simpler. It handles packing pointers. It just doesn't handle NULL.
I agree with you. Avoiding this complexity would be much better, but a bug is preventing me.
|
|---|