Skip to content
Browse files

echo-epoll.pl: use TCP_NODELAY

  • Loading branch information...
1 parent 48ae7c6 commit 5b0861b4d14190baa3920764a511cf738c0450da @hirose31 hirose31 committed
Showing with 4 additions and 0 deletions.
  1. +4 −0 echo-epoll.pl
View
4 echo-epoll.pl
@@ -1,6 +1,7 @@
use strict;
use warnings;
use Getopt::Long;
+use Socket qw(IPPROTO_TCP TCP_NODELAY);
use IO::Socket::INET;
use IO::Epoll;
use Fcntl;
@@ -89,8 +90,11 @@ sub with_perlio {
my $sock = $listener->accept;
my $sock_fd = fileno $sock;
$Sock_Holder[$sock_fd] = $sock;
+
+ setsockopt($sock, IPPROTO_TCP, TCP_NODELAY, 1);
my $flags = fcntl($sock, F_GETFL, 0) or die "fcntl GET_FL: $!";
fcntl($sock, F_SETFL, $flags|O_NONBLOCK) or die "fcntl SET_FL: $!";
+
epoll_ctl($epfd, EPOLL_CTL_ADD, $sock_fd, EPOLLIN) >= 0
|| die "epoll_ctl: $!\n";
} else {

0 comments on commit 5b0861b

Please sign in to comment.
Something went wrong with that request. Please try again.