in reply to Re^5: ... (Proof!)
in thread Non-blocking Reads from Pipe Filehandle

it's not a "fudge"

lpTotalBytesAvail and lpBytesLeftThisMessage are both LPDWORD. You pass zero to both. Yet, you want me to believe doing so results in passing a non-NULL pointer for lpTotalBytesAvail and a NULL pointer for lpBytesLeftThisMessage?

Replies are listed 'Best First'.
Re^7: ... (Proof!)
by BrowserUk (Patriarch) on Oct 01, 2008 at 07:34 UTC

    No. Both are passed as NULL-pointers:

    c:\test>buk-pipe.pl (XS)Win32::API::Call: prototype? 0 [n/a] (XS)Win32::API::Call: params[0].t=1, .u=76 (XS)Win32::API::Call: params[1].t=2, .u= (XS)Win32::API::Call: params[2].t=1, .u=1024 (XS)Win32::API::Call: params[3].t=2, .u=(null) (XS)Win32::API::Call: params[4].t=2, .u=(null) (XS)Win32::API::Call: params[5].t=2, .u=(null) (XS)Win32::API::Call: parameter 5 (P) is (null) (XS)Win32::API::Call: parameter 4 (P) is (null) (XS)Win32::API::Call: parameter 3 (P) is (null) (XS)Win32::API::Call: parameter 2 (N) is 1024 (XS)Win32::API::Call: parameter 1 (P) is (XS)Win32::API::Call: parameter 0 (N) is 76 (XS)Win32::API::Call: Calling ApiFunctionInteger() (XS)Win32::API::Call: ApiFunctionInteger returned 1 (XS)Win32::API::Call: freeing memory... (XS)Win32::API::Call: returning to caller. (XS)Win32::API::Call: returning 1. ...

    If you look closely, you'll see that I am not actually using lpTotalBytesAvail / $cAvail. I was in an early cut of the code, but then I realised that I didn't need to. It is easier to extract the information I need directly from the buffer.

    When I was using $cAvail, it was coded like to this:

    sub readlineMaybe { my $fh = shift; my $osfh = GetOsFHandle( $fh ) or die $^E; my( $bufsize, $buffer, $cAvail, $read ) = ( 1024, chr(0)x1024, chr +(0)x4, 0 ); PeekNamedPipe( $osfh, $buffer, $bufsize, $read, $cAvail, 0 ) or $^E == 109 or die $^E; print 'Available: ', unpack 'V', $cAvail; return if $^E == 109; my $eolPos = 1+index $buffer, $/; return '' unless $eolPos; sysread( $fh, $buffer, $eolPos ) or die $!; return $buffer; }

    Which produces this output:

    c:\test>buk-pipe.pl (XS)Win32::API::Call: prototype? 0 [n/a] (XS)Win32::API::Call: params[0].t=1, .u=76 (XS)Win32::API::Call: params[1].t=2, .u= (XS)Win32::API::Call: params[2].t=1, .u=1024 (XS)Win32::API::Call: params[3].t=2, .u=(null) (XS)Win32::API::Call: params[4].t=2, .u= (XS)Win32::API::Call: params[5].t=2, .u=(null) (XS)Win32::API::Call: parameter 5 (P) is (null) (XS)Win32::API::Call: parameter 4 (P) is (XS)Win32::API::Call: parameter 3 (P) is (null) (XS)Win32::API::Call: parameter 2 (N) is 1024 (XS)Win32::API::Call: parameter 1 (P) is (XS)Win32::API::Call: parameter 0 (N) is 76 (XS)Win32::API::Call: Calling ApiFunctionInteger() (XS)Win32::API::Call: ApiFunctionInteger returned 1 (XS)Win32::API::Call: freeing memory... (XS)Win32::API::Call: returning to caller. (XS)Win32::API::Call: returning 1. Available: 0 (XS)Win32::API::Call: prototype? 0 [n/a] (XS)Win32::API::Call: params[0].t=1, .u=76 (XS)Win32::API::Call: params[1].t=2, .u= (XS)Win32::API::Call: params[2].t=1, .u=1024 (XS)Win32::API::Call: params[3].t=2, .u=(null) (XS)Win32::API::Call: params[4].t=2, .u= (XS)Win32::API::Call: params[5].t=2, .u=(null) (XS)Win32::API::Call: parameter 5 (P) is (null) (XS)Win32::API::Call: parameter 4 (P) is (XS)Win32::API::Call: parameter 3 (P) is (null) (XS)Win32::API::Call: parameter 2 (N) is 1024 (XS)Win32::API::Call: parameter 1 (P) is (XS)Win32::API::Call: parameter 0 (N) is 76 (XS)Win32::API::Call: Calling ApiFunctionInteger() (XS)Win32::API::Call: ApiFunctionInteger returned 1 (XS)Win32::API::Call: freeing memory... (XS)Win32::API::Call: returning to caller. (XS)Win32::API::Call: returning 1. Available: 37 Got: 'Wed Oct 1 08:32:59 2008: some text' ...

    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.