From 9b39eec4d77db918ea80da1ae8129c83d2591be7 Mon Sep 17 00:00:00 2001 From: Piotr Roszatycki Date: Sun, 30 Oct 2016 01:25:24 +0200 Subject: [PATCH 1/2] Do not set if TCP_NODELAY is not available --- lib/HTTP/Server/PSGI.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/HTTP/Server/PSGI.pm b/lib/HTTP/Server/PSGI.pm index 7d9d81ef4..45ce88413 100644 --- a/lib/HTTP/Server/PSGI.pm +++ b/lib/HTTP/Server/PSGI.pm @@ -105,8 +105,10 @@ sub accept_loop { while (1) { local $SIG{PIPE} = 'IGNORE'; if (my $conn = $self->{listen_sock}->accept) { - $conn->setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) - or die "setsockopt(TCP_NODELAY) failed:$!"; + if (eval { TCP_NODELAY }) { + $conn->setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) + or die "setsockopt(TCP_NODELAY) failed:$!"; + } my $env = { SERVER_PORT => $self->{port}, SERVER_NAME => $self->{host}, From 0b33e362aef23984432af8589c0a1a7f443fb65b Mon Sep 17 00:00:00 2001 From: Piotr Roszatycki Date: Mon, 14 Nov 2016 00:55:48 +0100 Subject: [PATCH 2/2] Do not call `eval` in every request --- lib/HTTP/Server/PSGI.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/HTTP/Server/PSGI.pm b/lib/HTTP/Server/PSGI.pm index 45ce88413..186e6997b 100644 --- a/lib/HTTP/Server/PSGI.pm +++ b/lib/HTTP/Server/PSGI.pm @@ -13,11 +13,13 @@ use Plack::Util; use Stream::Buffered; use Plack::Middleware::ContentLength; use POSIX qw(EINTR); -use Socket qw(IPPROTO_TCP TCP_NODELAY); +use Socket qw(IPPROTO_TCP); use Try::Tiny; use Time::HiRes qw(time); +use constant TCP_NODELAY => try { Socket::TCP_NODELAY }; + my $alarm_interval; BEGIN { if ($^O eq 'MSWin32') { @@ -105,7 +107,7 @@ sub accept_loop { while (1) { local $SIG{PIPE} = 'IGNORE'; if (my $conn = $self->{listen_sock}->accept) { - if (eval { TCP_NODELAY }) { + if (defined TCP_NODELAY) { $conn->setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) or die "setsockopt(TCP_NODELAY) failed:$!"; }