Re: Lost data on socket - Can we start over politely?
From: Thomas Kratz (ThomasKratz_at_REMOVEwebCAPS.de)
Date: 03/30/04
- Next message: Gunnar Hjalmarsson: "Re: Variable substitution in variable name"
- Previous message: Martin L.: "Re: Syntax error"
- In reply to: Vorxion: "Lost data on socket - Can we start over politely?"
- Next in thread: Thomas Kratz: "Re: Lost data on socket - Can we start over politely?"
- Reply: Thomas Kratz: "Re: Lost data on socket - Can we start over politely?"
- Reply: Vorxion: "Re: Lost data on socket - Can we start over politely?"
- Reply: Vorxion: "Re: Lost data on socket - Can we start over politely?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 30 Mar 2004 18:27:41 +0200
Vorxion wrote:
> In light of some uh...disagreements, I've bent a bit. Hopefully it's taken
> as a token of goodwill. I could use the help, I'm willing to bend a bit to
> do it. SO...
>
> I've reworked this to both make it shorter, and so that my extra curly
> brackets are not present. I also implemented strict and warnings.
>
> In short, connect with anything and toss, say... 4000 thousand lines of
> input at the server. It should give up the ghost far early--somewhere
> around 1120-2200, depending on the phase of the moon. You'll note that if
> you're still connected, you can even send more data. It's purely a
> buffering issue.
>
> I've switched to using only buffered reads and writes on the socket fd's,
> so that's no longer the issue. I'm sure it was contributing, but nothing
> I'm doing here should be affecting it, to the best of my knowledge.
>
> Now that I've cleaned up my code (at least the majority) and am trying to
> appease some people, could I please ask for assistance? (Yes, there are a
> lot of variables in the our() statements that aren't used here...I trimmed
> about 1000 lines of code out this time instead of ~800.)
>
> If you just run it and toss input at it that's newline-separated, you'll
> see what I mean. I'm tossing 3900+ lines at it. It gives up at 1123
> somtimes, 2316 others, etc. Entirely arbitrary. It's not buffering
> corretly, but I know not why at this point.
[ 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.
Instead please try this server ( some quickly reduced code from a bigger
server ) and mini client. If this works for you, you could extend it.
I don't loose any data with this setup. And I don't even bother to set
unbuffered mode (tested on Win32).
If you look at the server code, you'll get an idea what is meant by "a
small but complete sample to reproduce the problem". The base
functionality you need is in there. And if I were able to understand, what
your code tries to do, I would be able to shorten it to that level too.
Regards
Thomas
++++ 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);
while ( $clsel->can_read(0.05) ) {
last unless $sock->sysread($buf, 1024, length($buf))
and (length($buf) <= $max_buf);
}
unless ( $buf ) {
print $log "error or close on socket\n";
$sock->close();
$sel->remove($sock);
next;
}
print $log "\n", length($buf), " bytes read\n";
print $log $buf;
}
}
++++ client ++++
use strict;
use warnings;
use IO::Socket;
my $sock = IO::Socket::INET->new(
PeerAddr => '235p008',
PeerPort => 4016,
Proto => 'tcp',
) or die "couldn't create socket";
my $i = 0;
while ( $sock->connected() ) {
last unless print $sock $i, 'x' x (100-length($i++)), "\n";
}
--
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</ #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..
- Next message: Gunnar Hjalmarsson: "Re: Variable substitution in variable name"
- Previous message: Martin L.: "Re: Syntax error"
- In reply to: Vorxion: "Lost data on socket - Can we start over politely?"
- Next in thread: Thomas Kratz: "Re: Lost data on socket - Can we start over politely?"
- Reply: Thomas Kratz: "Re: Lost data on socket - Can we start over politely?"
- Reply: Vorxion: "Re: Lost data on socket - Can we start over politely?"
- Reply: Vorxion: "Re: Lost data on socket - Can we start over politely?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|