in reply to filehandle/socket question

You are supposed to call seek between calls that use the same file handle in different ways (either one reading and one writing or one buffered and one unbuffered). seek($fh,0,0) in all the right places should fix your problem.

- tye        

Replies are listed 'Best First'.
Re^2: filehandle/socket question (seek)
by Forsaken (Friar) on Jul 18, 2004 at 17:24 UTC
    the problem is that the reading and writing happen in separate threads, hence making "between calls" a very obscure concept in this context :-) situations might occur where reads and writes actually happen at the very same moment, in fact, it probably happens all the time the way the script is set up. It *seems* to be working fine though, but since all the docs advised against I thought I'd better go and ask if there's a more proper approach.

      In that case, dup(2)ing the file handle is probably a better idea:

      open IN, "<&SOCKET" or die ...;

      though selecting a suitable non-bareword file handle scheme is even better.

      my $in = ...; open $in, "<&".fileno($sock) or die ...;

      Where the first "..." depends on what you find appropriate. "undef" works for modern versions of Perl. Or you can use IO::Handle or other module or just do { local(*IN); \*IN }.

      - tye