[En-Nut-Discussion] telnet crashes when recieving data at high rate

Harald Kipp harald.kipp at egnite.de
Wed Jun 8 15:39:52 CEST 2005


Hi Sander,

You forgot to take the TCP window into account.
When you set socket option SO_RCVBUF, this is
used as the initial window size. Ethernut announces
this size to the PC during connect and constantly
updates it during transmission.

If no thread on the Ethernut side reads TCP data
by calling fgets or similar, then the PC will fill
the buffer up to the window size and then switch to
window probing. No data will be send by the PC until
Ethernut announces, that there is buffer space available
again.

That's at least how it _should_ work. You may use
Ethereal to verify it.

Did you set SO_RCVBUF immediately after creating the
socket, before the connection is established?

On the other side, at the RS232 interface, data is
simply discarded when an overflow occurs. With Ethernut 2
you can use hardware handshake, while Ethernut 1 and 2
both support XON/XOFF. Use ioctl(UART_SETFLOWCONTROL)
for this. Only devUsartAvr supports flow control.

---- Snippet for usart0 ----
u_long flag = USART_MF_XONXOFF;
NutRegisterDevice(&devUsartAvr0, 0, 0);
uart0 = fopen("uart0", "r+b");
_ioctl(_fileno(uart0), UART_SETFLOWCONTROL, &flag);
---- Snippet End ----

See
http://www.ethernut.de/api/group__xgUsart.html

Check the Ethernut 2 hardware manual for correct
jumper settings for RTS/CTS handshake.

Harald


At 11:55 08.06.2005 +0000, you wrote:
>Hey,
>
>(This one's probably for Harald ;) )
>
>I use the telnet server from the "tcps" example project.
>In my project I have one telnet thread running, and multiple other threads 
>that might block the telnet thread for (for example) longer dan 0,5 sec.
>
>When I connect to the telnet server using Microsoft Windows's 
>Hyperterminal and I send a big plaintext file to the ethernut, it crashes 
>when other threads block the telnet thread from running. I monitored the 
>datarate to the ethernut, and it is constantly about 20 kbytes/sec.
>
>After some examining I found out (forgive me if I'm wrong) that when an 
>other thread is running (and telnet is blocked), hyperterminal continues 
>to send data (quite obvious). And because it can't be handled by the 
>telnet thread, this recieved data is stored on the heap until it is read 
>by (for example) fgets(). At least, this is what I think, because when the 
>other thread runs, the the free heap size keeps decreasing, until I read 
>some from the telnet stream using "fgets()".
>
>Now, my question is: why does the ethernut store all this data on the 
>heap? Why doesn't it just discard it when there is not enough free heap 
>space? In that case, the PC doesn't get an acknowlegde and sends it again. 
>Or is this not the way it works?
>
>And my main question: how can I prevent the ethernut from crashing? Is 
>there a way to implement somekind of flowcontrol, like <CTRL><Q> with 
>RS232? Or can I configure the tcp/ip stack somehow to prevent this crash?
>
>I use:
><code>
>
>#define TCPIP_BUFSIZ 1024
>u_short siz = TCPIP_BUFSIZ;
>NutTcpSetSockOpt(sock, SO_RCVBUF, &siz, sizeof(siz));
>
></code>
>
>to set the tcp/ip buffer size to 1024. Haven't changed any other params.
>
>Furthermore, I use WinAVR 2004-0720 (gcc version 3.4.1) and Nut/OS version 
>3.9.5.1 pre.
>
>Thanx in advance!
>Sander.
>
>
>_______________________________________________
>En-Nut-Discussion mailing list
>En-Nut-Discussion at egnite.de
>http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion




More information about the En-Nut-Discussion mailing list