#...
if ($req_method eq 'POST') {
DoPost($connex, $peeraddr, $req_content, $req_uri)
} elsif ($req_method eq 'GET') {
DoGet($connex, $peeraddr, $req_uri)
} else {
SendNotFound($connex)
}
}
print "Connection $connectno finished.\n";
#sleep 1 while ($connex->connected);
$connex->close;
print "Connection $connectno closed.\n\n";
}
sub DoPost {
#dummy Function
my ($c,$p,$req,$req_uri) = @_;
$c->send_file_response(qq|c:\\temp\\foo.dat|);
}
sub DoGet {
#dummy function
my ($c, $p, $uri) = @_;
$c->send_file_response(qq|c:\\temp\\foo.dat|);
}
sub SendNotFound {
#dummy function
my ($c) = @_;
$c->send_file_response(qq|c:\\temp\\foo.dat|);
}
&RunServer;
1;
####
...
Connection 69 at Fri Nov 11 16:10:53 2005 from 127.0.0.1
Connection: 69 Request: GET /
Connection 69 finished.
Connection 69 closed.
Connection 70 at Fri Nov 11 16:10:53 2005 from 127.0.0.1
Connection: 70 Request: GET /
Connection 70 finished.
Connection 70 closed.
...
####
#!/usr/bin/perl -w
use strict;
use threads;
use HTTP::Daemon;
$|++;
my $coreDaemon = HTTP::Daemon->new(LocalPort=>90) or die $!;
my $connectno = 0;
print "Listening...";
while(my $c = $coreDaemon->accept){
while (my $r = $c->get_request) {
if ($r->method eq 'GET') {
my ($thrd) = threads->create(\&GetHandler,$c, ++$connectno);
$thrd->detach;
#$c->send_file_response("c://temp//foo.dat");
}
else {
#$c->send_error(RC_FORBIDDEN)
$c->send_file_response("c://temp//failed.dat");
}
}
}
#from the old code
sub GetHandler {
my ($connex, $connectno) = @_;
my $peeraddr = $connex->peeraddr;
prin2log( "Connection $connectno started.");
$connex->send_file_response("c://temp//foo.dat");
prin2log( "Connection $connectno finished.");
#sleep 1 while ($connex->connected);
$connex->close;
prin2log( "Connection $connectno closed.\n");
}
#STDOUT messages will now go to this (non-filelocked) file
sub prin2log {
my ($str) = @_;
open(H,qq|>>c:\\temp\\foo.log|) or die qq|Cannot write to log: $!|;
print H $str . qq|\n|;
close(H);
}