If you have a modern perl, it will always be defined in Socket.pm, whether your system actually has it or not. In case your system does not have it, calling the constant will cause it
to croak with a message like "Your vendor has not defined Socket macro TCP_NODELAY". This is often what you want, so
you don't have to do anything in that case.
If you want to check at runtime and e.g. only turn nagle off if the constant really is there, you can check with a string eval, e.g:
# untested code
use Socket qw(IPPROTO_TCP)
my $has_nagle = eval "Socket::TCP_NODELAY(); 1";
...
if ($has_nagle) {
setsockopt($fh, IPPROTO_TCP,
Socket::TCP_NODELAY(), 1) ||
croak "Couldn't disable Nagle's algorithm: $!";
} else {
warn("Your system doesn't seem to support turning of Nagle's algor
+ithm\n");
}
(I also didn't try to import it in case you use a Socket.pm that doesn't even have the constant) |