Skip to content

Instantly share code, notes, and snippets.

@carlosmcevilly
Created November 25, 2013 06:28
Show Gist options
  • Save carlosmcevilly/7637145 to your computer and use it in GitHub Desktop.
Save carlosmcevilly/7637145 to your computer and use it in GitHub Desktop.
check whether Nagle's algorithm is on or off
#!/usr/bin/perl
# modified from the broken 'perldoc perlfunc' getsockopt example by adding one line (see comment below)
use strict;
use warnings;
use Socket qw(:all);
defined(my $tcp = getprotobyname("tcp"))
or die "Could not determine the protocol number for tcp";
socket(my $socket, PF_INET, SOCK_STREAM, 0)
or die "socket: $!"; # added this line
# my $tcp = IPPROTO_TCP; # Alternative
my $packed = getsockopt($socket, $tcp, TCP_NODELAY)
or die "getsockopt TCP_NODELAY: $!";
my $nodelay = unpack("I", $packed);
print "Nagle's algorithm is turned ", $nodelay ? "off\n" : "on\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment