Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Portably disabling Nagle's algorithm for TCP

by thospel (Hermit)
on Jan 02, 2005 at 23:08 UTC ( [id://418833]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Portably disabling Nagle's algorithm for TCP
in thread Portably disabling Nagle's algorithm for TCP

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)

Replies are listed 'Best First'.
Re^4: Portably disabling Nagle's algorithm for TCP
by mowgli (Friar) on Jan 03, 2005 at 17:38 UTC
    Mmmm. So is it safe to assume that if Socket does not define that macro, the platform we're running on actually does not support turning of Nagle's algorithm, or are there (non-totally obscure) platforms that don't have TCP_NODELAY but support doing this by other means?

    --
    mowgli

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://418833]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-18 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found