Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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)

  1. Lines 31 and 33 both assign to my $req. On 33, it's assigning to shift @ARGV.
  2. You assign $req to shift on line 51, but don't use it and don't pass anything in to error(), either.
  3. You don't use $pid from line 17. So, essentially, you're forking to create a child, then exiting the child immediately ... ?
  4. 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


In reply to Re: gopher server in < 1024B by dragonchild
in thread gopher server in < 1024B by beth

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (15)
    As of 2015-07-29 13:31 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (263 votes), past polls