Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: syswrite strange behaviour on some systems

by AgentM (Curate)
on Apr 02, 2001 at 20:46 UTC ( [id://69054]=note: print w/replies, xml ) Need Help??


in reply to syswrite strange behaviour on some systems

"To get unbuffered I/O, as much as possible..."

That doesn't make sense. If you want unbuffered I/O on a socket, then set it using Fcntl or using the appropriate socket option. But why not skip "unbuffered" and flush as necessary. This loop is inefficient and serves no obvious purpose. In fact, it may be what's confusing the WHOIS server since your loop is quite possibly sending a packet at a time (system-specific). Perhaps your $write is not '\0' ended which the server may expect? This is really guesswork but the real solution is use the REAL methods of unbuffered I/O. Perhaps since you're iterating through a list of servers, you'll want this to speed things up a bit?

AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
  • Comment on Re: syswrite strange behaviour on some systems

Replies are listed 'Best First'.
Re: Re: syswrite strange behaviour on some systems
by dash2 (Hermit) on Apr 02, 2001 at 20:56 UTC
    Thanks AgentM

    Well, my $write always ends "\015\012". Which should be nice... sounds like I am confused about I/O though. I read the FAQ which says:

    Perl does not support truly unbuffered output (except insofar as you can `syswrite(OUT, $char, 1)').

    But the packet at a time thing sounds like it might be the problem...

    Update What is weird is that the syswrite loop runs OK with any other server but not this one.

    dave hj~

      Well, the FAQ is misleading (*sigh*). Perl does support unbuffered I/O via syswrite and sysread. Perhaps they meant that Perl doesn't support unbuffered I/O via other functions such as print and printf (except that you can have the buffer autoflushed as described).

      <Update> And the difference between unbuffered and "command buffered" (as the FAQ calls it) is pretty subtle and usually unimportant so you might as well use "command buffered" for most things. The only time that I think it matters is that you can get into trouble by mixing buffered and unbuffered I/O to/from the same file handle. Nothing external to your script should be able to tell the difference between the two. </update>

      In particular, you don't have to specify a write length of 1 in order for syswrite to be unbuffered. Also, I encourage you to just leave the length argument off and write syswrite(WHOIS,$write).

      By writing things one byte at a time, your data might get sent with as few as one byte per packet. I could see this confusing a poorly written server.

              - tye (but my friends call me "Tye")
        Nice one Tye, thanks.

        Just one thing: I seem to recall having been bitten before by a versioning problem where some systems don't like syswrite unless you include the third "length" argument. Can't remember if this was a system thing, or a perl version thing. But it is worth knowing if you try to write XP Perl.

        dave hj~

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-16 04:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found