Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by mowgli (Friar)
on Jan 02, 2005 at 22:09 UTC ( [id://418823]=note: print w/replies, xml ) Need Help??


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

Thanks. How can I make sure that every system the script possibly runs on actually has that constant, though?

--
mowgli

  • Comment on Re^2: Portably disabling Nagle's algorithm for TCP

Replies are listed 'Best First'.
Re^3: Portably disabling Nagle's algorithm for TCP
by thospel (Hermit) on Jan 02, 2005 at 23:08 UTC
    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)
      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://418823]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 21:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found