Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

When to use Autoflush

by chorg (Monk)
on Dec 06, 2000 at 03:41 UTC ( [id://45125]=perlquestion: print w/replies, xml ) Need Help??

chorg has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

When printing to a socket, exactly when and why does one need to use autoflush?
_______________________________________________
"Intelligence is a tool used achieve goals, however goals are not always chosen wisely..."

Replies are listed 'Best First'.
Re: When to use Autoflush
by chromatic (Archbishop) on Dec 06, 2000 at 04:12 UTC
    Fastolfe has some good comments, but I want to expand a bit. There are additional reasons it might be necessary to turn off buffering:

    First, if you have a potentially slow connection, and it could take longer than your timeout to generate enough information to fill the buffer.

    Second, if the information you send has a positional aspect (as in, the HTTP headers must precede the content). If the potential exists that an error message may go out before the full headers, you may disable buffering.

    The disclaimer, of course, is that I'm not an expert here. :)

      Second, if the information you send has a positional aspect (as in, the HTTP headers must precede the content). If the potential exists that an error message may go out before the full headers, you may disable buffering.

      This actually brings us to another caveat: Don't mix buffered and unbuffered output. If your script writes to STDOUT and STDERR, and both of these somehow find their way through the network connection, note that STDOUT is buffered by default but STDERR is not. This is why you'll occasionally see "errors" appear before the actual output. The output is being mixed and naturally buffered output will appear later.

Re: When to use Autoflush
by Fastolfe (Vicar) on Dec 06, 2000 at 03:43 UTC
    Enabling autoflush is the same as setting $|=1. IO::Socket automatically sets autoflush mode on a created socket, so you shouldn't have to do it.

    If you're pushing large amounts of data, perhaps it's useful to have this turned off to take advantage of IO buffering, but for most network tasks, it's good to leave this turned on.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-03-29 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found