[28319] in Perl-Users-Digest
Perl-Users Digest, Issue: 9683 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 4 21:05:39 2006
Date: Mon, 4 Sep 2006 18:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 4 Sep 2006 Volume: 10 Number: 9683
Today's topics:
Re: (Off topic) Cyberwar question beartiger@gmail.com
Re: (Off topic) Cyberwar question <john@castleamber.com>
Re: (Off topic) Cyberwar question <mgarrish@gmail.com>
Re: (Off topic) Cyberwar question beartiger@gmail.com
Re: Cygwin error regarding profile.global <mgarrish@gmail.com>
Re: Cygwin error regarding profile.global beartiger@gmail.com
Re: Cygwin error regarding profile.global <mgarrish@gmail.com>
Re: Insert Log file into oracle table <mumia.w.18.spam+nospam.usenet@earthlink.net>
Problems detecting multiple clients <bryan@worldspice.net>
Problems detecting multiple clients <bryan@worldspice.net>
Re: Problems detecting multiple clients xhoster@gmail.com
Re: Problems detecting multiple clients <bryan@worldspice.net>
Re: Problems detecting multiple clients xhoster@gmail.com
Re: qr// doesn't handle m modifier? xhoster@gmail.com
Regexp slowdown chris.ritchie@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Sep 2006 15:25:14 -0700
From: beartiger@gmail.com
Subject: Re: (Off topic) Cyberwar question
Message-Id: <1157408714.780460.20230@b28g2000cwb.googlegroups.com>
Matt Garrish wrote:
> beartiger@gmail.com wrote:
>
> > Tad McClellan wrote:
> > > Skybuck <skybuck2000@hotmail.com> wrote:
> > >
> > >
> > > > Subject: (Off topic) Cyberwar question
> > >
> > >
> > > Making off topic posts is rude.
> > >
> > > Labelling an off topic post does not make it any less rude.
> >
> > Objecting to OT posts by replying to OT posts is stupid.
>
> Hmm, enlighten me as to how that does not apply to you?
I don't object to OT posts, dumbshit.
J
------------------------------
Date: 4 Sep 2006 22:37:30 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: (Off topic) Cyberwar question
Message-Id: <Xns9834B349E217Acastleamber@130.133.1.4>
"Jürgen Exner" <jurgenex@hotmail.com> wrote:
> Yours for a better Usenet
Writing versatel.nl about Skybuck might indeed help for a better Usenet,
ploinking nor posting "I ploinked you" does :-).
The post you replied to is IMNSHO sufficient enough to have his account
deleted, and I have informed versatel so.
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: 4 Sep 2006 16:11:17 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: (Off topic) Cyberwar question
Message-Id: <1157411477.505864.25330@e3g2000cwe.googlegroups.com>
beartiger@gmail.com wrote:
> Matt Garrish wrote:
> > beartiger@gmail.com wrote:
> >
> > > Tad McClellan wrote:
> > > > Skybuck <skybuck2000@hotmail.com> wrote:
> > > >
> > > >
> > > > > Subject: (Off topic) Cyberwar question
> > > >
> > > >
> > > > Making off topic posts is rude.
> > > >
> > > > Labelling an off topic post does not make it any less rude.
> > >
> > > Objecting to OT posts by replying to OT posts is stupid.
> >
> > Hmm, enlighten me as to how that does not apply to you?
>
> I don't object to OT posts, dumbshit.
>
You are a slow one. In simpler terms, then: why do you think your
objecting to his objecting serves any more purpose? If his objection is
pointless, yours is just as much so.
Matt
------------------------------
Date: 4 Sep 2006 17:34:12 -0700
From: beartiger@gmail.com
Subject: Re: (Off topic) Cyberwar question
Message-Id: <1157416452.861303.49770@m73g2000cwd.googlegroups.com>
Matt Garrish wrote:
> beartiger@gmail.com wrote:
>
> > Matt Garrish wrote:
> > > beartiger@gmail.com wrote:
> > >
> > > > Tad McClellan wrote:
> > > > > Skybuck <skybuck2000@hotmail.com> wrote:
> > > > >
> > > > >
> > > > > > Subject: (Off topic) Cyberwar question
> > > > >
> > > > >
> > > > > Making off topic posts is rude.
> > > > >
> > > > > Labelling an off topic post does not make it any less rude.
> > > >
> > > > Objecting to OT posts by replying to OT posts is stupid.
> > >
> > > Hmm, enlighten me as to how that does not apply to you?
> >
> > I don't object to OT posts, dumbshit.
>
> You are a slow one. In simpler terms, then: why do you think your
> objecting to his objecting serves any more purpose? If his objection is
> pointless, yours is just as much so.
I said I think it is stupid to post OT if you object to posting OT, and
I'm right. I never said objecting, in the abstract, was pointless,
wrong, or even stupid.
You, OTOH, are posting repeatedly and "ridiculously" OT, despite your
assertion that those who post "ridiculously" OT are "morons".
J
------------------------------
Date: 4 Sep 2006 16:05:14 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: Cygwin error regarding profile.global
Message-Id: <1157411114.039708.182680@i3g2000cwc.googlegroups.com>
beartiger@gmail.com wrote:
> Matt Garrish wrote:
> > beartiger@gmail.com wrote:
> >
> > > Matt Garrish wrote:
> > > > beartiger@gmail.com wrote:
> > > >
> > > > > anno4000@radom.zrz.tu-berlin.de wrote:
> > > > > > <beartiger@gmail.com> wrote in comp.lang.perl.misc:
> > > > > > > This post is simply to document the solution to a cygwin error so that
> > > > > > > those who have the same issue can find the solution when they do a
> > > > > > > Google Groups search. Please do not flame me for posting this here.
> > > > > >
> > > >
> > > > > Moron.
> > > > >
> > > >
> > > > You got the order of your respon<snip>
> > >
> > > Take a walk toward the closest shore and keep going until your hat
> > > floats.
> > >
> >
> > Yes, your wit is as ke<snip>
>
> Keep posting OT, you hypocritical moron.
>
Ooh, there's the M word again. Your expansive vocabulary well exhibits
your deep intellect.
Matt
------------------------------
Date: 4 Sep 2006 17:34:26 -0700
From: beartiger@gmail.com
Subject: Re: Cygwin error regarding profile.global
Message-Id: <1157416466.534409.11490@p79g2000cwp.googlegroups.com>
Matt Garrish wrote:
<snip>
> Ooh, there's the M word again. Your expansive vocabulary well exhibits
> your deep intellect.
Did you happen to notice that you yourself used the word, just three
posts ago?
The "moron" is you.
--Matt Garrish
And did you happen to notice that, despite your assertion that posting
OT is "stupid", you've now done it repeatedly?
Yes, I too am beginning to think that "moron" is a particularly
inarticulate way to describe you.
Now, you were saying....?
J
------------------------------
Date: 4 Sep 2006 18:02:46 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: Cygwin error regarding profile.global
Message-Id: <1157418166.433998.12850@e3g2000cwe.googlegroups.com>
beartiger@gmail.com wrote:
> Matt Garrish wrote:
> <snip>
> > Ooh, there's the M word again. Your expansive vocabulary well exhibits
> > your deep intellect.
>
> Did you happen to notice that you yourself used the word, just three
> posts ago?
>
> The "moron" is you.
> --Matt Garrish
>
> And did you happen to notice that, despite your assertion that posting
> OT is "stupid", you've now done it repeatedly?
>
> Yes, I too am beginning to think that "moron" is a particularly
> inarticulate way to describe you.
>
> Now, you were saying....?
>
>
> J
------------------------------
Date: Mon, 04 Sep 2006 22:38:33 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: Insert Log file into oracle table
Message-Id: <JV1Lg.3231$v%4.1017@newsread1.news.pas.earthlink.net>
On 09/04/2006 07:37 AM, mattjones@hotmail.co.uk wrote:
> addinall schrieb:
>
>> mattjones@hotmail.co.uk wrote:
>>> hi,
>>>
>>> Im having trouble loading a .log file into oracle. I can connect to the
>>> database and i can insert data (that i define in an INSERT statement).
>>> I eventually need to filter specific info from the .log files (there
>>> are alot of them - and this script provides an automated process) but
>>> for now i just want to read the whole script into a table!
>>>
>>> CURRENT SCRIPT:
>>> #!/usr/central/bin/perl -w
>>>
>>> use strict;
>>> use DBI;
>>>
>>> my $dbh = DBI ->connect("dbi:Oracle:SERVER", "DATABASE", "PASSWORD")
>>> or die "Couldn't connect to database: $DBI::errstr\n";
>>>
>>>
>>> my $rows = $dbh->do("
>>> INSERT INTO LOGS VALUES ('160820061-fst.log', '5', '0', 'FASTSEARCH',
>>> '0', 'inversions', '0', 'conflicting') ");
>>>
>>> $dbh->disconnect;
>>>
>>> exit;
>>> ##### I have also tried the following and putting $LOG into one of the
>>> values but I just get the value '1' returned!
>>> my $LOG = open (LOG, "/home/USRNAME/PERL/hello.log");
>>>
>>> my @data = <LOG>;
>>> close LOG;
>>>
>>> Any ideas?
>> I'm assuming you have a CLOB field to put the data into?
>> If so, your second attempt is the one that is correct.
>> If ORACLE is returning a '1', that generally reads
>> "One row updated".
>>
>> Fire up SQL+, or a PL/SQL session, or TOAD and do a
>>
>> DESCRIBE TABLE_NAME ;
>>
>> and let us know what is in the table. Then perhaps do a
>>
>> SELECT COUNT(*) FROM TABLE_NAME ;
>>
>> to see if any of your attempts have made it into the
>> database.
>>
>> I assume that some of your entries are just going to contain strings
>> like:
>> '160820061-fst.log'
>>
>> ORACLE isn't hard, be persitant, it will become clear!
>>
>> Cheers,
>> Mark Addinall.
>>
>> Right, so I've created a CLOB field (didn't realise!) and my code is now:
>
> #!/usr/central/bin/perl -w
>
> use strict;
> use DBI;
>
> #!/usr/central/bin/perl -w
>
> use strict;
> use DBI;
>
> my $dbh = DBI ->connect("dbi:Oracle:SERVER", "DATABASE", "PASSWORD")
> or die "Couldn't connect to database: $DBI::errstr\n";
>
> my $LOG = open (LOG, "/home/USERNAME/PERL/hello.log");
>
When open succeeds, it returns '1,' so $LOG contains '1.'
> my @data = <LOG>;
If you want to put the entire log file into the database, you
should slurp it into a scalar like so:
my $data = do { local $/; <LOG> };
> close LOG;
>
> my $rows = $dbh->do("
> INSERT INTO LOGS VALUES ( 'wesdf', 'sdfg', 'dfg', 'fdg', 'dfg', 'dfg',
> 'dfg', 'dfg', $LOG) ");
>
Since $LOG contains the useless value '1,' you probably want
to put the actual log data in there:
'dfg', 'dfg', '$data') ");
There also might be a need for escaping the data in $data.
> $dbh->disconnect;
>
> exit;
>>> The 9th value to be inserted '$LOG' is supposed to read in hello.log. But i am still getting the value 1. Im using TOAD so can check it straight away by refreshing the schema browser.
>
> I want to get this working before I think about what i have to enter
> into the fields. But for your info: i have to search through 1 log file
> at a time and pull out specific information (which are not delimited!).
> Some of the lines are repetitious so i can't just define a value to
> pull out. I have written some code on this and it basically pulls out
> the lines i want - I was hoping that TOAD would let me then, filter out
> the info on display!
>
>>> Thanks for your help.....ive been working on this script for a while so this was my last resort - I was just given this to do and I hadn't even used oracle or written any PERL before!!!
>
> Matt
>
I'm neither a Perl nor DB expert, but this might help you some:
use strict;
use warnings;
use DBI;
open (LOG, 'hello.log') or die("Open failure: $!\n");
my $data = do { local $/; <LOG> };
close (LOG);
# I don't have $Oracle$.
my $dsn = "DBI:mysql:database=test;host=localhost";
my $dbh = DBI->connect($dsn,$ENV{USER},'')
or die("Connection failure: $!\n");
my $qdata = quotemeta($data);
$dbh->do("insert into logfiles values (0, '2006-09-04',
'$qdata')")
or die("insertion failure: $!\n");
$dbh->disconnect;
__END__
Notice how I placed quotes around $qdata in the insertion. I
also quoted metacharacters to be sure they wouldn't mess up
the insertion.
------------------------------
Date: 4 Sep 2006 15:05:58 -0700
From: "samasama" <bryan@worldspice.net>
Subject: Problems detecting multiple clients
Message-Id: <1157407558.931482.7240@e3g2000cwe.googlegroups.com>
Hi...
I'm trying to detect multiple clients connected to a SOCK_STREAM
server. I'm doing this via a hash. The actual detecting part is going
fine. The problem I'm running into however takes place when a second
client connects from the same ip address (multiple clients)... When a
second connection is made from the same host, it errors out and
disconnects that second connection as it should, but when the first
(original) connection disconnects and tries to re-connect it doesn't
work. This is because the first (original) connections key in the hash
does not get deleted. I've been banging my head into the desk for a few
weeks trying to figure out how to get that key deleted, and properly.
Any help, advice, pointers, brutal criticism is very much welcome and
appreciated.
#!/usr/bin/perl
use warnings;
use diagnostics;
use strict;
use IO::Socket;
use POSIX qw(:sys_wait_h);
our %ip_conns; # hash of connected clients
our $time_to_die = 0;
# Globals for the socket
our $SERVER;
our $CLIENT;
$SIG{CHLD} = \&handle_sigchld;
$SIG{INT} = $SIG{TERM} = \&handle_default;
our $banner =
"\%rwhois V-1.5:000082:00 rwhois.foo.bar (Rwhois Server version)";
our $foo; # Temp for messing with chk_multi_conn
my $pid = fork;
exit if $pid;
die "Couldn't fork: $!\n" unless defined($pid);
POSIX::setsid() || die "Can't start a new session: $!";
$SERVER = IO::Socket::INET->new(
Proto => 'tcp',
LocalAddr => '0.0.0.0',
LocalPort => '4321',
Listen => SOMAXCONN,
Reuse => 1
);
die "WSRwhois : Can't setup server : $!\n " unless $SERVER;
print "[ Server $0 accepting clients ]\n";
until ($time_to_die) {
while ( $CLIENT = $SERVER->accept() ) {
$foo = $CLIENT;
$ip_conns{$CLIENT} = $CLIENT->peerhost;
my $conn_ret = chk_multi_conn();
if ($conn_ret == 1 ) {
delete $ip_conns{$CLIENT};
shutdown($CLIENT, 2); }
my $kidpid = fork;
die "Fork: $!\n" unless defined($kidpid);
if ( $kidpid == 0 ) {
shutdown( $SERVER, 1 );
$CLIENT->autoflush;
print $CLIENT "$banner\015\012";
while ( sysread( $CLIENT, $_, 1024 ) ) {
next unless /\S/;
if (/-quit/) {
print $CLIENT "\%ok\015\012";
shutdown( $CLIENT, 2 );
}
}
delete $ip_conns{$CLIENT};
exit(0);
}
else { # Let the parent do some stuff
}
}
}
sub chk_multi_conn {
my %count = ();
my $times;
foreach my $keys ( keys %ip_conns ) {
my $value = $ip_conns{$keys};
print "#DEBUG Inside chk_multi_conn()\n"; # DEBUG
print "#DEBUG \%ip_conns = $keys => $value\n"; # DEBUG
print "#DEBUG\n"; # DEBUG
print "#DEBUG \$CLIENT = $CLIENT\n"; # DEBUG
$times = $count{$value}++;
}
if ( $times >= 1 ) {
print $CLIENT
"\%error Only 1 connection allowed per host.\n";
return (1);
}
else {
return (0); }
}
sub handle_sigchld {
delete $ip_conns{$foo}; # Just to be sure
my $pid = wait; # Wait for children to die
$SIG{'CHLD'} = \&handle_sigchld;
}
sub handle_default {
$time_to_die = 1; # Kill daemon
}
--
samasama
------------------------------
Date: 4 Sep 2006 15:09:32 -0700
From: "samasama" <bryan@worldspice.net>
Subject: Problems detecting multiple clients
Message-Id: <1157407772.657367.26570@e3g2000cwe.googlegroups.com>
Hi...
I'm trying to detect multiple clients connected to a SOCK_STREAM
server. I'm doing this via a hash. The actual detecting part is going
fine. The problem I'm running into however takes place when a second
client connects from the same ip address (multiple clients)... When a
second connection is made from the same host, it errors out and
disconnects that second connection as it should, but when the first
(original) connection disconnects and tries to re-connect it doesn't
work, and gets treated as a second connection. This is because the
first (original) connection key in the hash does not get deleted. I've
been banging my head into the desk for a few weeks trying to figure out
how to get that key deleted, and properly.
Any help, advice, pointers, brutal criticism is very much welcome and
appreciated.
#!/usr/bin/perl
use warnings;
use diagnostics;
use strict;
use IO::Socket;
use POSIX qw(:sys_wait_h);
our %ip_conns; # hash of connected clients
our $time_to_die = 0;
# Globals for the socket
our $SERVER;
our $CLIENT;
$SIG{CHLD} = \&handle_sigchld;
$SIG{INT} = $SIG{TERM} = \&handle_default;
our $banner =
"\%rwhois V-1.5:000082:00 rwhois.foo.bar (Rwhois Server version)";
our $foo; # Temp for messing with chk_multi_conn
my $pid = fork;
exit if $pid;
die "Couldn't fork: $!\n" unless defined($pid);
POSIX::setsid() || die "Can't start a new session: $!";
$SERVER = IO::Socket::INET->new(
Proto => 'tcp',
LocalAddr => '0.0.0.0',
LocalPort => '4321',
Listen => SOMAXCONN,
Reuse => 1
);
die "WSRwhois : Can't setup server : $!\n " unless $SERVER;
print "[ Server $0 accepting clients ]\n";
until ($time_to_die) {
while ( $CLIENT = $SERVER->accept() ) {
$foo = $CLIENT;
$ip_conns{$CLIENT} = $CLIENT->peerhost; # key it
my $conn_ret = chk_multi_conn(); # Check it
if ($conn_ret == 1 ) {
delete $ip_conns{$CLIENT};
shutdown($CLIENT, 2); }
my $kidpid = fork;
die "Fork: $!\n" unless defined($kidpid);
if ( $kidpid == 0 ) {
shutdown( $SERVER, 1 );
$CLIENT->autoflush;
print $CLIENT "$banner\015\012";
while ( sysread( $CLIENT, $_, 1024 ) ) {
next unless /\S/;
if (/-quit/) {
print $CLIENT "\%ok\015\012";
shutdown( $CLIENT, 2 );
}
}
delete $ip_conns{$CLIENT};
exit(0);
}
else { # Let the parent do some stuff
}
}
}
sub chk_multi_conn {
my %count = ();
my $times;
foreach my $keys ( keys %ip_conns ) {
my $value = $ip_conns{$keys};
print "#DEBUG Inside chk_multi_conn()\n"; # DEBUG
print "#DEBUG \%ip_conns = $keys => $value\n"; # DEBUG
print "#DEBUG\n"; # DEBUG
print "#DEBUG \$CLIENT = $CLIENT\n"; # DEBUG
$times = $count{$value}++;
}
if ( $times >= 1 ) {
print $CLIENT
"\%error Only 1 connection allowed per host.\n";
return (1);
}
else {
return (0); }
}
sub handle_sigchld {
delete $ip_conns{$foo}; # Just to be sure
my $pid = wait; # Wait for children to die
$SIG{'CHLD'} = \&handle_sigchld;
}
sub handle_default {
$time_to_die = 1; # Kill daemon
}
--
samasama
------------------------------
Date: 04 Sep 2006 23:34:45 GMT
From: xhoster@gmail.com
Subject: Re: Problems detecting multiple clients
Message-Id: <20060904193459.240$Ts@newsreader.com>
"samasama" <bryan@worldspice.net> wrote:
> Hi...
> I'm trying to detect multiple clients connected to a SOCK_STREAM
> server. I'm doing this via a hash. The actual detecting part is going
> fine. The problem I'm running into however takes place when a second
> client connects from the same ip address (multiple clients)... When a
> second connection is made from the same host, it errors out and
> disconnects that second connection as it should, but when the first
> (original) connection disconnects and tries to re-connect it doesn't
> work, and gets treated as a second connection. This is because the
> first (original) connection key in the hash does not get deleted.
You have a forking server. You are deleting the entry from the child's
hash, which has no affect on the parent's hash.
> Any help, advice, pointers, brutal criticism is very much welcome and
> appreciated.
>
> #!/usr/bin/perl
>
> use warnings;
> use diagnostics;
> use strict;
> use IO::Socket;
> use POSIX qw(:sys_wait_h);
>
> our %ip_conns; # hash of connected clients
>
> our $time_to_die = 0;
>
> # Globals for the socket
> our $SERVER;
> our $CLIENT;
Why do you have all the "our" rather than using "my"? $SERVER and $CLIENT
probably shouldn't be declared so early.
> $SIG{CHLD} = \&handle_sigchld;
>
> $SIG{INT} = $SIG{TERM} = \&handle_default;
>
> our $banner =
> "\%rwhois V-1.5:000082:00 rwhois.foo.bar (Rwhois Server version)";
>
> our $foo; # Temp for messing with chk_multi_conn
Why do you think this is necessary?
...
>
> sub chk_multi_conn {
> my %count = ();
> my $times;
> foreach my $keys ( keys %ip_conns ) {
> my $value = $ip_conns{$keys};
> print "#DEBUG Inside chk_multi_conn()\n"; # DEBUG
> print "#DEBUG \%ip_conns = $keys => $value\n"; # DEBUG
> print "#DEBUG\n"; # DEBUG
> print "#DEBUG \$CLIENT = $CLIENT\n"; # DEBUG
> $times = $count{$value}++;
> }
I don't see how this is supposed to do anything useful at all. The final
value of $times depends on what order the hash keys are stored it, which
is indeterminate. Besides, Wouldn't it make a lot more sense to reverse
the %ip_conns, so you can just look up into it using the rather than
looping over it?
> if ( $times >= 1 ) {
> print $CLIENT
> "\%error Only 1 connection allowed per host.\n";
> return (1);
> }
> else {
> return (0); }
>
> }
>
> sub handle_sigchld {
> delete $ip_conns{$foo}; # Just to be sure
At this point, $foo just contains the last connection accepted. There is
no particular reason to think the connection just ended is the same as the
last one accepted, so you are deleting the wrong thing
> my $pid = wait; # Wait for children to die
What you need to do is keep a hash mapping child pid to child connection
IP, so that you can lookup what connection just ended according to which
child just exited.
Also, you should use waitpid in a loop, rather than wait. If two children
exit in close proximity, your handle might only get called one time, so
only one of them would be harvested.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 4 Sep 2006 17:07:00 -0700
From: "samasama" <bryan@worldspice.net>
Subject: Re: Problems detecting multiple clients
Message-Id: <1157414820.189550.246280@74g2000cwt.googlegroups.com>
xhoster@gmail.com wrote:
Keep in my mind I'm a big friggin noob, though from my code I'm sure
that's obvious :)
This is also my first program.
>
> You have a forking server. You are deleting the entry from the child's
> hash, which has no affect on the parent's hash.
I was deleting here...
while ( $CLIENT = $SERVER->accept() ) {
$foo = $CLIENT;
$ip_conns{$CLIENT} = $CLIENT->peerhost;
my $conn_ret = chk_multi_conn();
if ($conn_ret == 1 ) {
delete $ip_conns{$CLIENT};
shutdown($CLIENT, 2); }
Which would be in the parent... The other deletes was shotgun
troubleshooting...
> > # Globals for the socket
> > our $SERVER;
> > our $CLIENT;
I thought this was the proper way to delcare globals?
Also, this is a broken down version of 900 line program. I needed to
delcare them early for use in sub throughout the parent and child.
> Why do you have all the "our" rather than using "my"? $SERVER and $CLIENT
> probably shouldn't be declared so early.
I thought this was the proper way to delcare globals?
Also, this is a broken down version of 900 line program. I needed to
delcare them early for use in sub throughout the parent and child.
> > our $foo; # Temp for messing with chk_multi_conn
> Why do you think this is necessary?
Once again, voodoo programming and shotgun troubleshooting :)
I got to the point where I was trying anything.
I thought perhaps handle_sigchld would/was get confused if I used
$CLIENT
> ...
> >
> > sub chk_multi_conn {
> > my %count = ();
> > my $times;
> > foreach my $keys ( keys %ip_conns ) {
> > my $value = $ip_conns{$keys};
> > print "#DEBUG Inside chk_multi_conn()\n"; # DEBUG
> > print "#DEBUG \%ip_conns = $keys => $value\n"; # DEBUG
> > print "#DEBUG\n"; # DEBUG
> > print "#DEBUG \$CLIENT = $CLIENT\n"; # DEBUG
> > $times = $count{$value}++;
> > }
>
> I don't see how this is supposed to do anything useful at all. The final
> value of $times depends on what order the hash keys are stored it, which
> is indeterminate. Besides, Wouldn't it make a lot more sense to reverse
> the %ip_conns, so you can just look up into it using the rather than
> looping over it?
>
I don't understand : )
I pulled that out of the cookbook, for checking dups in a hash.
> At this point, $foo just contains the last connection accepted. There is
> no particular reason to think the connection just ended is the same as the
> last one accepted, so you are deleting the wrong thing
*nod*
> > my $pid = wait; # Wait for children to die
>
> What you need to do is keep a hash mapping child pid to child connection
> IP, so that you can lookup what connection just ended according to which
> child just exited.
>
hehe, huh?
> Also, you should use waitpid in a loop, rather than wait. If two children
> exit in close proximity, your handle might only get called one time, so
> only one of them would be harvested.
>
Noted, and thanks for pointing that out.
Thanks period : )
--
samasama
------------------------------
Date: 05 Sep 2006 00:42:43 GMT
From: xhoster@gmail.com
Subject: Re: Problems detecting multiple clients
Message-Id: <20060904204257.569$6x@newsreader.com>
"samasama" <bryan@worldspice.net> wrote:
> xhoster@gmail.com wrote:
>
> Keep in my mind I'm a big friggin noob, though from my code I'm sure
> that's obvious :)
> This is also my first program.
>
> >
> > You have a forking server. You are deleting the entry from the child's
> > hash, which has no affect on the parent's hash.
>
> I was deleting here...
> while ( $CLIENT = $SERVER->accept() ) {
> $foo = $CLIENT;
> $ip_conns{$CLIENT} = $CLIENT->peerhost;
> my $conn_ret = chk_multi_conn();
> if ($conn_ret == 1 ) {
> delete $ip_conns{$CLIENT};
> shutdown($CLIENT, 2); }
>
> Which would be in the parent... The other deletes was shotgun
> troubleshooting...
That only deletes connections which are denied due to chk_multi_conn. What
about the connections that are acceptedable and then at some point down the
road get closed naturally?
>
> > > # Globals for the socket
> > > our $SERVER;
> > > our $CLIENT;
>
> I thought this was the proper way to delcare globals?
> Also, this is a broken down version of 900 line program. I needed to
> delcare them early for use in sub throughout the parent and child.
You might want to pass them into the subs, instead of using them globally.
Yes, it can be more annoying to write initially (and no, I don't always
follow my own advice), but it is generally worth it in the long run.
> > > sub chk_multi_conn {
> > > my %count = ();
> > > my $times;
> > > foreach my $keys ( keys %ip_conns ) {
> > > my $value = $ip_conns{$keys};
> > > print "#DEBUG Inside chk_multi_conn()\n"; # DEBUG
> > > print "#DEBUG \%ip_conns = $keys => $value\n"; # DEBUG
> > > print "#DEBUG\n"; # DEBUG
> > > print "#DEBUG \$CLIENT = $CLIENT\n"; # DEBUG
> > > $times = $count{$value}++;
> > > }
> >
> > I don't see how this is supposed to do anything useful at all. The
> > final value of $times depends on what order the hash keys are stored
> > it, which is indeterminate. Besides, Wouldn't it make a lot more sense
> > to reverse the %ip_conns, so you can just look up into it using the
> > rather than looping over it?
> >
> I don't understand : )
> I pulled that out of the cookbook, for checking dups in a hash.
I don't know cookbook it is from, or what it looks like originally, but
I'm pretty sure it didn't look like that. You must have screwed something
up in the conversion. One thing to note is that $CLIENT doesn't appear
productively anywhere in that code. How can it tell if CLIENT shows up
more than once when it doesn't even care about what CLIENT is?
What you end up with is that %count holds the count of the number of times
each IP address is connected, and $times holds that count for one
(unpredictably) arbitrary IP address.
>
> > At this point, $foo just contains the last connection accepted. There
> > is no particular reason to think the connection just ended is the same
> > as the last one accepted, so you are deleting the wrong thing
>
> *nod*
>
> > > my $pid = wait; # Wait for children to die
> >
> > What you need to do is keep a hash mapping child pid to child
> > connection IP, so that you can lookup what connection just ended
> > according to which child just exited.
> >
>
> hehe, huh?
after you fork, you do something like
$pid_list{$pid}=$CLIENT->peerhost;
Then when "wait" gives you a pid, you look it up in the %pid_list hash to
see what IP needs to be deleted from %ip_conns.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 04 Sep 2006 23:05:03 GMT
From: xhoster@gmail.com
Subject: Re: qr// doesn't handle m modifier?
Message-Id: <20060904190517.113$YE@newsreader.com>
anno4000@radom.zrz.tu-berlin.de wrote:
> <xhoster@gmail.com> wrote in comp.lang.perl.misc:
> > Michele Dondi <bik.mido@tiscalinet.it> wrote:
> > > On 1 Sep 2006 10:57:38 -0700, adam@irvine.com wrote:
> > >
> > > >The following program doesn't do what I expected. The second and
> > > >third "print" statements print, but the first one doesn't. It looks
> > > >as though when the match operator uses a regular expression
> > > >constructed with qr//, the "m" modified that should have been stored
> > > >in the regular expression is ignored. Did I do something wrong, or
> > > >is this a bug in
> >
> > I get the same behavior as you do, using 5.8.8.
>
> Strange. I see the problem with 5.6.1 but not with 5.8.8 (nor with
> bleadperl 5.9.4).
Just to make sure we aren't miscommunicating, I get this:
$ perl -le '$pat="a\$"; $re=qr/$pat/m; my $s="a\nb"; \
print $re; print $s=~/$re/?"good":"bad" '
(?m-xis:a$)
bad
This is perl, v5.8.8 built for i686-linux-thread-multi
This is perl, v5.8.0 built for i386-linux-thread-multi
This is perl, v5.8.7 built for x86_64-linux
This is perl, v5.8.3 built for x86_64-linux-thread-multi
(If I replace the $re with the literal string "(?m-xis:a$)", I get
"good" in all situations.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 4 Sep 2006 17:33:29 -0700
From: chris.ritchie@gmail.com
Subject: Regexp slowdown
Message-Id: <1157416409.679949.6410@p79g2000cwp.googlegroups.com>
I have a subroutine that does a rather extensive expression match (the
expression is ~80 characters long). It's looking for this expression
in strings limited to 500 characters.
The script runs just fine on many input strings, then slows
considerably without any discernable cause. My debug output looks
like:
Starting regexp match (string size 380)...
<~5 seconds>
Done.
Starting regexp match (string size 381)...
<~9 seconds>
Done.
Starting regexp match (string size 382)...
<~14 seconds>
Done.
I might think that the string size is too large for the expression
(though there's no reason it should be), but it matches previous
strings of size close to 500 with ease. Also, when I limit the size to
100, it will have the same slow down around 70 or 80.
I would wonder about memory management because the entire script is a
few thousand lines long, but there aren't many global variables. And
it does not slow down elsewhere. The code is almost all subroutines
with 'my' variables. I assume these variables are deallocated when the
subroutine is done, please correct me if I'm wrong.
What else could it be?
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 9683
***************************************