[En-Nut-Discussion] telnet crashes when recieving data athigh rate
Sander Smeenk
sandersmeenk at hotmail.com
Wed Jun 8 16:34:17 CEST 2005
Hey harald,
It appears you are right, it doesn't crash when the heap is full as I
thought, it was my own program that caused the crash. Sorry to bother you
with this ;)
But now I have another question: I still use the "tcps example", and when I
use hyperterminal to send data, it takes 23 seconds (!!) to send a file of
30 kilobytes.
This means about 1,2 kB/sec. I think this is very slow, any idea how this is
possible? I included the tcps.c I use (modified it to not do anything but
recieving). It does appear to me that the PC uses 100% CPU when sending the
file. This is strange too, because it's an Intel 2,4 gHz :) Maybe
hyperterminal just sucks I thought, so I tried teraterm, but same problem
with that program: 23 sec.
Any help would be appreciated...
btw, my tcps file (renamed it to telnet.c) can be found at:
http://smaankers.jepraatpoep.nl/telnet.c
Thanx in advance,
Sander.
>From: Harald Kipp <harald.kipp at egnite.de>
>Reply-To: "Ethernut User Chat (English)" <en-nut-discussion at egnite.de>
>To: "Ethernut User Chat (English)" <en-nut-discussion at egnite.de>
>Subject: Re: [En-Nut-Discussion] telnet crashes when recieving data athigh
>rate
>Date: Wed, 08 Jun 2005 15:39:52 +0200
>
>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
>
>_______________________________________________
>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