Perl 5.8.8, Solaris, And SOMAXCONN
[Moozik Cranes Tangled Up]
When setting up a listening socket, you pass an integer value to listen() indicating the number of incoming connections that can be queued. Often a handy way of doing that is to just say hey, just use whatever maximum value your OS will allow. The Socket module exports the constant SOMAXCONN to give you that very max value from the OS. In fact, instead of calling listen() ourselves, we can just pass the value in the constructor.
my $socket = IO::Socket::INET->new(
LocalPort => 5000,
Listen => SOMAXCONN,
Proto => 'tcp',
Reuse => 1
);
The problem is that SOMAXCONN on Solaris 9 always returns 5 regardless of the OS max value. Our value of SOMAXCONN:
perl -MSocket -e 'print Socket::SOMAXCONN()'
5
But our OS says:
/usr/sbin/ndd /dev/tcp tcp_conn_req_max_q
1024
So, the moral of this little blog post is that if you're writing a daemon to listen on a port for incoming connections and you're on Solaris, SOMAXCONN probably isn't the value you think it is. Not that I got bitten by this today or anything ;-)
Leave a comment