diff options
Diffstat (limited to 'gmi.pl')
-rwxr-xr-x | gmi.pl | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -7,7 +7,7 @@ use warnings; use 5.010; #use diagnostics; -our $VERSION = 'v0.0.10'; +our $VERSION = 'v0.0.11'; # Modules use IO::Socket::SSL; # CPAN @@ -57,7 +57,7 @@ const our %GEM_RES_CODES => ( const our @VALID_DEFAULT_SETTINGS => qw/bind ports tls assume_index dir_listing root working_dir cert_key_dir - log_file log_to_stdout default_mime cert_key_dir_write_warning fork/; + log_file log_to_stdout default_mime cert_key_dir_write_warning fork timeout/; const our @VALID_VHOST_SETTINGS => qw/auto_cert assume_index dir_listing root cert key default_mime/; @@ -71,6 +71,7 @@ my %ssl_config = ssl_config($config); my $working_dir = working_dir($config); my $cert_key_dir = cert_key_dir($config); my $out = logging($config); +my $timeout = timeout_secs($config); select $out; ## no critic (InputOutput::ProhibitOneArgSelect) local $OUTPUT_AUTOFLUSH = 1; ssl_vhost_cert_key(\%ssl_config); @@ -110,7 +111,7 @@ while () { # We do this because 'naughty' people/bots can clog up the ports doing nothing. local $SIG{ALRM} = sub { timeout($cl, $clhost, $cl_sni) }; - alarm 5; # TODO make magic number not magic. + alarm $timeout; # TODO make magic number not magic. if (! sysread $cl, $data, $KBYTE) { $log = "$clhost - ($cl_sni) sysread failed"; alarm 0; @@ -509,7 +510,8 @@ sub ssl_config { SSL_version => '!SSLv2:!SSLv3:!TLSv1:!TLSv1_1', SSL_fast_shutdown => 1, - Timeout => 2, + Timeout => 2, # !! Nothing to do with the config option !! + # used if /no/ SSL connection was established SSL_error_trap => 1, #SSL_server => 1, ); @@ -755,4 +757,20 @@ sub maybe_fork { } } +sub timeout_secs { + my ($cert_ref) = @_; + if (exists $cert_ref->{default}{timeout}) { + if ($cert_ref->{default}{timeout} =~ /^(\d*)$/) { + return $1; + } + else { + serr("Timeout value ($cert_ref->{default}{timeout}) is invalid. Using 5 seconds."); + return 5; + } + } + else { + return 5; + } +} + 1; |