Subject: Re: getsockopt(TCP_DEFER_ACCEPT) value change

From: Eric Dumazet <[email-masked]>
Date: Tue, 05 Jan 2010 15:45:26 +0100

Le 05/01/2010 15:11, Eric Dumazet a écrit :

> Nothing... really... we can round the value, and we indeed round it in 2.6.32
> 
> defer value is given in second by user, and converted to number of retransmits by kernel.
> 
> Program assumption is wrong.

BTW, previous kernels were rounding too :

1 -> 3
2 -> 3
3 -> 3
4 -> 6
5 -> 6
6 -> 6
7 -> 12
8 -> 12
9 -> 12
10 -> 12
11 -> 12
12 -> 12
13 -> 24
14 -> 24
15 -> 24
16 -> 24
17 -> 24
18 -> 24
19 -> 24

New kernel (or other sysctl settings, I didnot check) :

1 -> 3
2 -> 3
3 -> 3
4 -> 9
5 -> 9
6 -> 9
7 -> 9
8 -> 9
9 -> 9
10 -> 21
11 -> 21
12 -> 21
13 -> 21
14 -> 21
15 -> 21
16 -> 21
17 -> 21
18 -> 21
19 -> 21

#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

int main(int argc, char *argv[])
{
   int i, val1 = 12, val2;
   socklen_t len = sizeof(val2);
   int fd;
     fd = socket(PF_INET, SOCK_STREAM, 0);
   if (fd < 0) {
       perror("socket");
       return -1;
   }
   for (i = 1; i < 20 ; i++) {
     val1 = i;
     if (setsockopt(fd, SOL_TCP, TCP_DEFER_ACCEPT, &val1, sizeof(val1))) {
       perror("setsockopt");
       return -1;
     }
     if (getsockopt(fd, SOL_TCP, TCP_DEFER_ACCEPT, &val2, &len)) {
       perror("getsockopt");
       return -1;
     }
   printf("%d -> %d\n", i, val2);
   }
   return 0;
}