From bd2ba4b7dae2fa7f1979dc44693186c30b3c1a17 Mon Sep 17 00:00:00 2001 From: Thomas Schwery Date: Sun, 15 Aug 2010 19:30:07 +0200 Subject: [PATCH] Multithreading okay --- gopher.pl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gopher.pl b/gopher.pl index a8f51ed..d4206e2 100644 --- a/gopher.pl +++ b/gopher.pl @@ -7,7 +7,6 @@ # TODO: # - Support for a list of tags # - Cleanup on ctrl-c -# - Multithreading # - ... use strict; @@ -19,8 +18,9 @@ use HTML::FormatText; use Text::Wrap; use Date::Parse; use Date::Format; +use threads; -our $port = 70; +our $port = 7071; our %entries = (); $SIG{INT} = \&signal_handler_interrupt; @@ -32,6 +32,16 @@ drop_privileges('nobody'); while (1) { my $listen_socket = $socket->accept(); + print "New incoming connection ...\n"; + my $thr = threads->create(\&connection_thread, $listen_socket); + print "Joining ..."; + $thr->join(); + print "Joined\n"; +} + +sub connection_thread { + my ($listen_socket) = @_; + print "New Thread\n"; $_ = <$listen_socket>; s/\r*\n*//g; s/\t.*//g; # Don't care about the parameters now ... @@ -58,6 +68,8 @@ while (1) { $listen_socket->send($blog_entries . "\r\n"); $listen_socket->send("\r\n.\r\n"); } + + $listen_socket->close(); } sub generate_header {