On Fri, Jul 04, 2003 at 11:02:19AM -0300, Cristiano Lincoln Mattos wrote:
>
> Hi Everyone,
>
> I'm having a few problems with POE 0.26 reading files on ActivePerl
> 5.61 (build 635),
> on WinXP/2K.
>
> If I use a ReadWrite wheel to read the file, I never get any
> Input events at all -- it basically stops, and the CPU starts rising
> steadily. From what I gather, using ReadWrite to read files on Win32
> is unsupported because you cant set filehandles to non-blocking on
> Win32, right?
>
> Well, I noticed that FollowTail works fine on Win32. So, just to
> temporarily fix my problem, I hacked up a little Wrapper around
> FollowTail... it sets the SeekBack parameter to larger than the file's
> size so it can read the entire file, then goes on processing the input
> event's until it notices the entire file has been read. The code is
> attached
> below.
>
> It works, but I'm not really satisfied with this solution. I'd
> like to use Readwrite features such as input throttling with highMark
> and lowMark. A few questions:
>
> - Why is FollowTail able to read files in Win32 while ReadWrite
> isn't?
FollowTail uses a timer event to poll the file for new data. It does
not use POE::Kernel's select_read() anymore. ReadWrite uses
select_read() and select_write() extensively, which don't work with
Win32 plain files.
> - What are the main problems in this type of approach i've taken?
> I know I'm generating twice the number of input events here (followtail's,
> and for whoever's using my Reader object), but from my tests, that
> doesn't seem to slow things down so much.
A better approach, at least for plain disk files, is to just access them
directly. select() on plain files always indicates that they are ready
to be read from or written to. POE::Wheel::ReadWrite's main feature is
non-blocking operations, but plain files rarely block anyway. This is
especially the case with operating systems that perform disk caching.
> - How could I implement input throttling decently on top of
> FolloTail ?
You would probably need to modify FollowTail directly to support this.
POE::Wheel::ReadWrite has pause_input() and resume_input() events that
manipulate select_read() internally.
FollowTail does not use select_read() for input, but it does use a timer
loop to periodically check the file for new input. pause_input() and
resume_input() could be implemented for FollowTail by destroying and
re-creating the timer event. I think they might be as easy as:
sub pause_input {
my $self = shift;
if (defined $self->[SELF_STATE_READ]) {
$self->delay($self->[SELF_STATE_READ]);
}
}
sub resume_input {
my $self = shift;
if (defined $self->[SELF_STATE_READ]) {
$self->delay($self->[SELF_STATE_READ], $self->[SELF_INTERVAL]);
}
}
Let me know if that works, and I'll put it into 0.2601.
> - Would the best thing to do be writing a new object, using POE's
> internal calls for select and so on, forgetting FollowTail entirely?
No. Win32 (perhaps only ActivePerl) does not support select() on plain
files. That's why POE::Wheel::ReadWrite doesn't work.
The proper way to resolve this would be to create a POE::Loop::Win32
(perhaps POE::Loop::ActivePerl if Cygwin Perl does not have this
problem). With the Win32-isms firmly supported at the low level, all
the higher-level wheels and components will suddenly work.
[code]
-- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/