Very sorry for forgetting to cc reply into tech@.

-------- Forwarded Message --------
Subject: Re: [patch] Set TCP send buffer size only when tcpbench client
works in TCP mode
Date: Thu, 10 May 2018 17:56:25 +0800
From: Nan Xiao <n...@chinadtrace.org>
To: Alexander Bluhm <alexander.bl...@gmx.net>

Hi Bluhm,

Thanks for your reply!

Since from the comment of code (line 66):

struct {
        int       Sflag;        /* Socket buffer size (tcp mode) */
        ......
}

So I think maybe this should work on TCP only. BTW, if it works on both
TCP/UDP, I think differentiate error message will be better:

Index: tcpbench.c
===================================================================
RCS file: /cvs/src/usr.bin/tcpbench/tcpbench.c,v
retrieving revision 1.52
diff -u -p -r1.52 tcpbench.c
--- tcpbench.c  19 Sep 2016 18:58:39 -0000      1.52
+++ tcpbench.c  10 May 2018 09:54:42 -0000
@@ -895,7 +895,7 @@ client_init(struct addrinfo *aitop, int
                        if (ptb->Sflag) {
                                if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
                                    &ptb->Sflag, sizeof(ptb->Sflag)) == -1)
-                                       warn("set TCP send buffer size");
+                                       warn("set %s send buffer size", 
TCP_MODE? "TCP" : "UDP");
                        }
                        if (connect(sock, ai->ai_addr, ai->ai_addrlen) != 0) {
                                if (ai->ai_next == NULL)



Thanks!
On 5/10/2018 5:39 PM, Alexander Bluhm wrote:
> On Thu, May 10, 2018 at 03:10:53PM +0800, Nan Xiao wrote:
>> Per my understanding, the tcpbench.Sflag (Socket buffer size) should
>> only take effect when working in TCP mode.
> 
> Why?  The kernel provides socket buffers for all protocols.  Userland
> can set them and the kernel does the appropriate things.  There is
> no reason to restrict setting socket buffer size to TCP.
> 
>> But according to my testing,
>> it also works when tcpbench client is in UDP mode:
>>
>> (1) Set buffer size less than DEFAULT_UDP_PKT (1500 - 28):
>> # tcpbench -u -S 1471 127.0.0.1
>> tcpbench: write: Message too long
> 
> Of course it works for UDP.  That is the expected behavior.  UDP
> is atomic and if the buffer is too small for a packet, you cannot
> send.
> 
>> So I think maybe it is need to check whether client is in TCP mode
>> before setting buffer size, and apologize if I am wrong:
> 
> I would be very surprized by this silent restriction of tcpbench.
> If I test UDP, I want to see what the kernel does if I change the
> socket buffer size.
> 
> bluhm
> 

-- 
Best Regards
Nan Xiao(肖楠)

Reply via email to