How to set TCP_NODELAY to the BSD connector in Solaris?

I am trying to disable the Nagle algorithm for a BSD socket using:

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

but the compiler claims that TCP_NODELAY not been seen before:

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

This is a complete list of inclusions for the file in which it is located:

 #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. Did I miss something?

All this on a Solaris 8 machine.

+6
c ++ c solaris sockets
source share
2 answers

It looks like you are missing #include <netinet/tcp.h> - where TCP_... defines live.

+12
source share

I do not have a Solaris window, only Linux.

 grep -ri TCP_NODELAY /usr/include/* 

leads to:

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

Perhaps you could try something like this?

+2
source share

All Articles