If your system actually has the constant, it will nowadays
be in Socket.pm.
Query, set, unset:
use Socket qw(IPPROTO_TCP TCP_NODELAY);
sub nagle(*;$) {
my $fh = shift;
if (!@_) {
return unpack("I", getsockopt($fh, IPPROTO_TCP, TCP_NODELAY) |
+|
croak "Could not get Nagle state: $!") ? 0 : 1;
}
if (shift) {
setsockopt($fh, IPPROTO_TCP, TCP_NODELAY, 0) ||
croak "Couldn't enable Nagle's algorithm: $!";
} else {
setsockopt($fh, IPPROTO_TCP, TCP_NODELAY,1) ||
croak "Couldn't disable Nagle's algorithm: $!";
}
}
(A lot of perl code floating on the internet incorrectly uses SOL_SOCKET as level, possibly because the cookbook
gets it wrong).
This functionality should only be used if it makes sense though.