Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set TCP_NODELAY on BSD socket on Solaris?

I am trying to turn off Nagle's algorithm for a BSD socket using:

setsockopt(newSock, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof flag);

but the compiler claims TCP_NODELAY hasn't been seen before:

error: `TCP_NODELAY' undeclared (first use this function)

This is the full list of includes for the file this is in:

#include <arpa/inet.h>
#include <fcntl.h>
#include <iostream>
#include <netdb.h>
#include <string>
#include <sys/socket.h>
#include <sys/types.h>
using namespace std;

I also have the -lnsl and -lsocket linker options, but it just won't compile. Am I missing something?

All of this is on a Solaris 8 machine.

like image 351
Ben S Avatar asked Jun 25 '09 18:06

Ben S


2 Answers

Looks like you are missing #include <netinet/tcp.h> - that's where TCP_... defines live.

like image 187
Nikolai Fetissov Avatar answered Oct 02 '22 18:10

Nikolai Fetissov


I don't have a Solaris box handy, only a Linux one.

grep -ri TCP_NODELAY /usr/include/*

results in:

/usr/include/linux/tcp.h:#define TCP_NODELAY            1       /* Turn off Nagle's algorithm. */
/usr/include/netinet/tcp.h:#define      TCP_NODELAY      1      /* Don't delay send to coalesce packets  */

Perhaps you could try something similar?

like image 22
EightyEight Avatar answered Oct 02 '22 17:10

EightyEight