Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^4: sysread/syswrite wrappers

by vsespb (Chaplain)
on Oct 12, 2016 at 14:44 UTC ( #1173845=note: print w/replies, xml ) Need Help??


in reply to Re^3: sysread/syswrite wrappers
in thread sysread/syswrite wrappers

only reason for using sysread/syswrite with select is because they don't wait for complete input.
No, primary reason to use sysread/syswrite with select, is because readline and print are not working with select.

And I reason to use select in application, is that I have several processes which send message, and I am not sure which of them will send next message and when, so I need to select between their pipes.
And if your messages are not some exact multiple of 4K, the last line of every 4k block will be a partial message, and your wrapper will therefore block until the next 4k block has been filled and passed through, before that message will be completed
That's true for blocking pipes, anyway. Post is about blocking pipes. Yes, with blocking pipes master process performance would be limiting factor for all processes. I didn't see when it's a problem in my IPC applications - either master is fast, or messages are rare/small, or child need a reply anyway, just after sending a message.

Replies are listed 'Best First'.
Re^5: sysread/syswrite wrappers
by BrowserUk (Pope) on Oct 12, 2016 at 15:10 UTC
    No, primary reason to use sysread/syswrite with select, is because readline and print are not working with select.

    Of course they do:

    #! perl -sw use strict; use Win32::Socketpair qw[ winsocketpair ]; my( $fd1, $fd2 ) = winsocketpair(); my $v = ''; vec( $v, my $fn1 = fileno( $fd1 ), 1) = 1; vec( $v, my $fn2 = fileno( $fd2 ), 1) = 1; while( 1 ) { if( select( my $vin = $v, my $vout = $v, undef, undef ) > 0 ) { if( vec( $vout, $fn1, 1 ) ) { print( $fd1 "hello\n" ) or last; } if( vec( $vin, $fn2, 1 ) ) { defined( my $buffer = <$fd2> ) or last; print "read: $buffer"; } } } __END__ C:\test>junk88 read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello read: hello Terminating on signal SIGINT(2) read: hello

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.

        Yes, they do!

        print is just syswrite + a little; readline is just sysread with a loop looking for the current value of $/.

        In other words, your wrappers are exactly equivalent to those built-ins; except that they are in C and thus vastly more efficient; and well tried and tested thus more likely to be correct.

        As for that; there is a huge difference between quoting the manual and understanding what it says.

        The *ONLY REASON* print and readline are said to "not work with select", is because they will block if they receive a partial message, thus preventing the code from getting back to the select. IE. They do exactly what your wrappers do; except they're more likely correct.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        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". I knew I was on the right track :)
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1173845]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2019-12-08 16:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?