Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: TCP - setting TCP_NODELAY (aka disabling Nagle's algorith)  (Read 6217 times)

0 Members and 1 Guest are viewing this topic.

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
TCP - setting TCP_NODELAY (aka disabling Nagle's algorith)
« on: August 08, 2012, 02:46:40 pm »
Hello.
I really like SFML however it seems like it lacks one very important feature - cross-platform setsockopt() equivalent like boost::asio has, or more simply - the only thing that 99% people use that function for - setting TCP_NODELAY (or setting TCP_DELAY to false, well, basically disabling that annoying for games Nagle's algorith).
In Windows on pure sockets you can do it for example that way (there are better ways I think, it's just random code I found that does it):

int opt = -1;
if (setsockopt(sock_fd, IPPROTO_TCP, TCP_NODELAY, (char *)&opt, sizeof(opt)))
  printf("Error disabling Nagle's algorithm.\n");

However it would be much nicer is SFML had cross-platform simple function to disable TCP_DELAY on tcp socket. Some libraries I saw just have that simple function, however I like SFML much more and I'd like to use it. Unfortunatelly, SFML doesn't have option to set socket option, nor it has simple function to set TCP_NODELAY. For a bit faster game turning that delay off really helps and allows you not to mess with UDP.

How can I achieve it in SFML? I want cross platform code, because my server is linux, and game is for windows.

Thanks in advance!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: TCP - setting TCP_NODELAY (aka disabling Nagle's algorith)
« Reply #1 on: August 08, 2012, 02:57:57 pm »
The Nagle's algorithm is disabled in all SFML sockets. So it's even simpler than what you requested :P
Laurent Gomila - SFML developer

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TCP - setting TCP_NODELAY (aka disabling Nagle's algorith)
« Reply #2 on: August 08, 2012, 03:06:35 pm »
Wow! I'm amazed, thats GREAT news! Thanks for quick answer Laurent, and thanks for that amazing library!