From owner-freebsd-questions Wed Feb 2 6:54:35 2000 Delivered-To: freebsd-questions@freebsd.org Received: from relay01.chello.nl (smtp.chello.nl [212.83.68.144]) by builder.freebsd.org (Postfix) with ESMTP id CCCB1406A for ; Wed, 2 Feb 2000 06:54:28 -0800 (PST) Received: from eeyore.sebster.com ([213.46.5.19]) by relay01.chello.nl (InterMail vK.4.02.00.00 201-232-116 license a4501b83b68dc3e36f6046e1d8586abe) with ESMTP id <20000202150211.IDET7564.relay01@eeyore.sebster.com> for ; Wed, 2 Feb 2000 16:02:11 +0100 Received: by eeyore.sebster.com (Postfix, from userid 1000) id 225685DC3; Wed, 2 Feb 2000 15:54:09 +0100 (CET) Subject: TCP_NODELAY To: freebsd-questions@freebsd.org Date: Wed, 2 Feb 2000 15:54:08 +0100 (CET) X-Mailer: ELM [version 2.4ME+ PL61 (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=ELM949503248-12168-0_ Content-Transfer-Encoding: 7bit Message-Id: <20000202145409.225685DC3@eeyore.sebster.com> From: sebster@sebster.com (Sebastiaan van Erk) Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --ELM949503248-12168-0_ Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hi there, I tried the following code to disable Nagle's algorithm, but it doesn't seem to work: int d = 1; setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (void *)&d, sizeof(d)); One reason this bugs me is because I do succeed in Java to turn off Nagle's algorithm, and it DOES work, and furthermore, in ssh2 the code used to turn off Nagle's algorithm is identical to the code above. My ssh is very slow, so I thought this could be the problem (since telnet is really fast). My OS is FreeBSD 3.4 STABLE. If I compile the program under Linux, Solaris, or HP-UX, it works fine. I attached both the C program and the Java program which I use to test the TCP_NODELAY settings. To compile and run the C program simply do a cc -o tcpdelay tcpdelay.c ./tcpdelay To compile and run the Java program simply do a javac TCPDelayTest.java java TCPDelayTest true (By using true/false as a parameter one can enable/disable Nagle's algorithm to see the difference in speed) Can anybody tell me what is going wrong? Greetings, Sebastiaan van Erk --ELM949503248-12168-0_ Content-Type: text/plain; charset=ISO-8859-1 Content-Disposition: attachment; filename=tcpdelay.c Content-Description: tmp/wave/comm.c Content-Transfer-Encoding: 7bit #include #include #include #include #include #include #include #include #include #include #define MESSAGE_LENGTH 20 void SendData(); void ReceiveData(); int main() { unsigned short initport, sendport, receiveport; int initskt, sendskt, receiveskt; struct sockaddr_in addr; size_t addrlen; struct timeval tp1, tp2; struct timezone tpz; int i=0; int window_size=(int)(1.5 * MESSAGE_LENGTH); int nodelay=1; initskt = OpenTcpSocket(&initport); printf("Opened init socket on port %d\n", initport); listen(initskt, 1); setsockopt(initskt, IPPROTO_TCP, TCP_NODELAY, (void *)&nodelay, sizeof(nodelay)); receiveskt = OpenTcpSocket(&receiveport); printf("Opened receive socket on port %d\n", receiveport); /* setsockopt(receiveskt, SOL_SOCKET, SO_RCVBUF, (char *)&window_size, sizeof(window_size)); */ addrlen = sizeof(struct sockaddr_in); if (getsockname(initskt, (struct sockaddr *)&addr, &addrlen) != 0) { fprintf(stderr, "Unable to get send socket name.\n"); exit(1); } if (connect(receiveskt, (struct sockaddr *)&addr, addrlen) < 0) { fprintf(stderr, "Failed to connect to target socket."); exit(1); } printf("Connected receivesocket & initsocket.\n"); sendskt = accept(initskt, (struct sockaddr *)&addr, &addrlen); printf("Accepted connection.\n"); for (i=0; i<100; i++) { gettimeofday(&tp1, &tpz); SendData(sendskt); ReceiveData(receiveskt); gettimeofday(&tp2, &tpz); printf("Total time needed to send & receive %d bytes: %1.5f\n", MESSAGE_LENGTH, ((float)((1000000*tp2.tv_sec + tp2.tv_usec) - ((1000000*tp1.tv_sec) + tp1.tv_usec)))/1000000); } return(0); } int OpenTcpSocket(unsigned short *portp) { int skt; struct sockaddr_in addr; size_t addrlen; unsigned short port; if ((skt = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) <= 0) { fprintf(stderr, "Can't create socket.\n"); exit(1); } bzero(&addr, sizeof(struct sockaddr_in)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = 0; port = 0; addr.sin_port = htons(port); if (bind(skt, (struct sockaddr *)&addr, sizeof(addr)) != 0) { fprintf(stderr, "Unable to bind socket to port.\n"); exit(1); } return(skt); } void SendData(int skt) { char buf[MESSAGE_LENGTH+1]; int nbytes, i; for (i=0; i