Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Flaky Server (IO::Socket and IO::Select Question)

by Arguile (Hermit)
on Jun 12, 2001 at 12:59 UTC ( [id://87752]=note: print w/replies, xml ) Need Help??


in reply to Flaky Server (IO::Socket and IO::Select Question)

I'm not even close to the level where I can answer this yet but one statement caught my interest.

"In fairness I should note that this entry does make it into the log, about 8 minutes after the link fails"

I recently was browsing Brother Dominus's tome on "Suffering from Buffering" and that statement seem like it might be a like problem. On the off chance it does correlate, I though I'd mention it.

An excerpt from the tome:

In Perl, you can't turn the buffering off, but you can get the same benefits by making the filehandle hot. Whenever you print to a hot filehandle, Perl flushes the buffer immediately. In our log file example, it will flush the buffer every time you write another line to the log file, so the log file will always be up-to-date.

[snip]

If you happen to be using the FileHandle or IO modules, there's a nicer way to write this:

use FileHandle; # Or `IO::Handle' or `IO::'-anything-else ... LOG->autoflush(1); # Make LOG hot. ...

Replies are listed 'Best First'.
Re: Re: Flaky Server (IO::Socket and IO::Select Question)
by ginseng (Pilgrim) on Jun 13, 2001 at 01:13 UTC

    Thank you Arguile.

    I did have some trouble with buffering, but not in these areas. STDIN and STDOUT are autoflushed when connected to an interactive terminal, but not when redirected. Because of this, my code worked fine when run directly, but hung miserably when run under djb's tcpserver. i finally added:

    # turn on autoflush for STDIN and STDOUT select STDIN; $|=1; select STDOUT; $|=1; select STDERR;

    to deal with that.

    Likewise in the log file, I'm doing much the same thing, except I'm not keeping the filehandle when not in use.

    sub logger { # set up a file handle for a log file. open LOG, ">>$log_file" or die("Could not open log file for appendin +g."); select LOG; $|=1; select STDERR; print LOG "weldd $$: ", scalar(localtime), " @_\n"; close LOG; }

    Alas, the IO::Socket stuff shouldn't require autoflushing, per perldoc:

    perldoc IO::Socket
    ...
    NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
    
    As of VERSION 1.18 all IO::Socket objects have aut-
    oflush turned on by default. This was not the case
    with earlier releases.
    
    NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
    ...
    

    The uptake of this is that, while I did have problems with buffering, I don't think it's the current problem :(

    ginseng

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found