AW: [En-Nut-Discussion] fprintf() on streamed TCP socket

Oliver Schulz olischulz at web.de
Thu Dec 11 18:50:08 CET 2003


Hi Dusan,

> When I use multiple fprintf() calls with small amount of
> data, it seems to
How many bytes are a "small amount of data"?


> I think that output is buffered till incoming message fits in
> stream output
> buffer.

I assume, that you use something like that:

sock = NutTcpCreateSocket();
NutTcpConnect(...);
fd = _fdopen ((int) sock, ...);

If you then use fprintf (fd, ...), Nut/OS routes the final output to
NutTcpDeviceWrite (implemented in net/tcpsock.c), which provides some data
buffering: When fprintf generates more than 64 bytes output data, the packet
is immediately sent. If less then 64 bytes output data, the data is written
into a 256 byte sized buffer, until it is full. In this case the packet is
sent.

> ...
>      if (NutTcpSetSockOpt(sock, TCP_MAXSEG, &tcp_mss,
> sizeof(tcp_mss)))
>          LOG_MSG("%u. Cannot set MSS sock opt\n", id);
>
> When I am initially sending large data (38kB) with fwrite_P()
> of MY_TCP_MSS
> size, packets are wide enough. With fprintf() not. Any idea ?
>
By using the TCP_MAXSEG option, you just set the maximum network segment
size, i.e. the maximum packet size Nut/Net sends to the nic.
Writing more than TCP_MAXSEG bytes to a TCP socket will just break the data
into several network packets.

The buffer size (256) and the break even value (64) used in
NutTcpDeviceWrite is currently not configurable. Perhaps this is an issue to
change in the future.

Cheers,
Oliver.




More information about the En-Nut-Discussion mailing list