Re: Lost data on socket - Can we start over politely?
From: Vorxion (vorxion_at_knockingshopofthemind.com)
Date: 03/30/04
- Next message: Tore Aursand: "Re: Remove empty elements of an array"
- Previous message: Gerald Jones: "perl modules -> RPM resources???"
- In reply to: Thomas Kratz: "Re: Lost data on socket - Can we start over politely?"
- Next in thread: Tassilo v. Parseval: "Re: Lost data on socket - Can we start over politely?"
- Reply: Tassilo v. Parseval: "Re: Lost data on socket - Can we start over politely?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Mar 2004 16:56:06 -0500
In article <4069a132.0@juno.wiesbaden.netsurf.de>, Thomas Kratz wrote:
>[ code snipped ]
>
>Sorry, but the code is still too cluttered to debug it. I have tried,
>really, for about 45 minutes, then I gave up.
Thanks for the effort though. However, this example you gave (I just woke
up in the middle of the "night" and decided to check mail and news quickly,
so I haven't tested it yet) is very helpful. One thing I don't understand
about it though...
>++++ server ++++
>
>use strict;
>use warnings;
>
>use IO::File;
>use IO::Select;
>use IO::Socket;
>
>my $max_buf = 10240;
>
>my $sel = IO::Select->new();
>
>my $srv = IO::Socket::INET->new(
> Proto => 'tcp',
> LocalPort => 4016,
> Listen => SOMAXCONN,
> ReuseAddr => 1,
>);
>
>$sel->add($srv);
>
>die "couldn't create socket" unless $srv;
>
>my $log = IO::File->new('server.log', '>') or die $!;
>$log->autoflush(1);
>
>while ( 1 ) {
>
> foreach my $sock ( $sel->can_read(0.05) ) {
>
> if ( $sock == $srv ) {
>
> my $new = $srv->accept();
> $new->autoflush(1);
> print $log "new connection from ", $new->peerhost,
> ':', $new->peerport, "\n";
> $sel->add($new);
>
> next;
> }
>
> my $buf = '';
> my $clsel = IO::Select->new($sock);
There... -Every- time you go through the loop, you're reconstructing
$clsel as a single-element-holding object containing the current
iteration's object? Could I inquire as to why you're doing this instead of
simply performing the following check on $sel instead of $clsel? Is it
simply a speed optimisation for that block, or is there something inherently
safer in what you're doing that would cause problems if you tried using
$sel?
> while ( $clsel->can_read(0.05) ) {
> last unless $sock->sysread($buf, 1024, length($buf))
> and (length($buf) <= $max_buf);
> }
Wait a second...Doh. *lightbulb* You come in the first time on $sel, but
you're rebuilding $clsel so that you can purely stay -on that socket- until
it's drained? I think I'm startng to see. Could you confirm?
That, and one thing is curious--the docs for foreach() say that adding and
removing elements from something from a list used for the loop is a Bad
Thing[tm]. You're modifying $sel any time there's a connect or disconnect.
Doesn't that throw the foreach() loop out of sync? Not at all a criticism,
it's just that I've had fresh experience with foreach() and changed lists
and elements thereof, and that part of the docs is fresh in my mind. I'm
curious why this causes no difficulties in your example.
This example is definitely worth a shot. If it works properly, I'll have to
adapt it, but it would be tremendously helpful to see a working example,
using select, that doesn't drop data on the floor. I'll let you know how it
turns out. I was just very curious as to why you're rebuilding a
single-element IO::Select handle each iteration, rather than simply having
an 'else' block as an inverse of the server accept(). I -think- I see now,
though.
And I saw your note about not using non-blocking. Gotcha.
Thanks -very much- for the code to test, and will try tonight!
-- Vorxion - Member of The Vortexa Elite
- Next message: Tore Aursand: "Re: Remove empty elements of an array"
- Previous message: Gerald Jones: "perl modules -> RPM resources???"
- In reply to: Thomas Kratz: "Re: Lost data on socket - Can we start over politely?"
- Next in thread: Tassilo v. Parseval: "Re: Lost data on socket - Can we start over politely?"
- Reply: Tassilo v. Parseval: "Re: Lost data on socket - Can we start over politely?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|