I think it's generally a good idea to use \015\012 instead of \r\n when doing something such as this (i.e. network coding). The reason is \n can change depending on what platform you're running. Hopefully this won't push you past the 1024 byte limit. 8^)
For reference, this is documented in perlop, under the "Quote and Quote-like Operators" section, in the paragraph starting with "All systems use the"
| [reply] [d/l] [select] |
Does this code actually work? I've been looking at golfing it and found a few oddities. Here's the code as run through B::Deparse:
BEGIN { $^W = 1; }
use IO::Socket;
use strict 'refs';
local $/ = "\r\n";
my $port = '7070';
my $root = '/home/beth/gopher/gopher';
die "can't chroot: $!\n" unless chroot $root;
local $SIG{'HUP'} = 'IGNORE';
exit if my $pid = fork;
die "Couldn't create socket: $!\n" unless my $sock = 'IO::Socket::INET
+'->new('LocalPort', $port, 'Type', SOCK_STREAM(), 'Listen', 1, 'Reuse
+', 1);
my $s = $sock->accept;
while (defined(my $req = <$s>)) {
chomp(my $req = shift @ARGV);
$req = '/' . $req;
&error unless -r $req;
$req .= '/.cache' if -d _;
printfile($req);
close $sock;
}
sub printfile {
use strict 'refs';
open FILE, shift @_;
binmode FILE;
print $s <FILE>;
close FILE;
}
sub error {
use strict 'refs';
my $req = shift @_;
print $s "iBad Request: $! \tfake\t(NULL)\t0" . $/;
}
Please note the following: (line#'s from your code)
- Lines 31 and 33 both assign to my $req. On 33, it's assigning to shift @ARGV.
- You assign $req to shift on line 51, but don't use it and don't pass anything in to error(), either.
- You don't use $pid from line 17. So, essentially, you're forking to create a child, then exiting the child immediately ... ?
- Unless I'm mistaken, you'll only ever serve one request for one client, then leave ... ?
I'm not trying to rip it apart, but I couldn't understand it to golf it. :-(
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
I shouldn't have to say this, but any code, unless otherwise stated, is untested
| [reply] [d/l] [select] |