TCP Sockets Simultaneous Read andWrite

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

TCP Sockets Simultaneous Read andWrite

PeterAdamsen
This post was updated on .
Hello,

I am having problems of simultaneous reading and writing to a TCP
socket with LwIP, FreeRTOS, AVR32 (EWK1100).

I know that lwip_write() and lwip_read() calls are not threadsafe and I have seen a lot of other forum
threads discussing this and the use semaphores of lwip_select(). - I do not think this is the problem here.

I have boiled down my program to only have one thread with one lwip_write() call and one delay of app. 1 msec. (Nolwip_read() call !). (See source code below.)

When I connect a terminal program from a PC, it will start receiving the messages. When sending a few messages (Just pressing ENTER) from the terminal program to the AVR32, it will make the transmission from the AVR pause for exactly 10 sec. - Then resume. this can be repeated a number of time whereafter transmission completely stops.

I have traced down the 10sec pause to be in api_lib.c, netconn_write(), sys_mbox_fetch(conn->mbox, NULL); call.

A WireShark recording is attached. The problem appear at time: 20.147 and again at 34.903.

LwIP_ReadWrite2.pcapng

My PC is 192.168.120.17 and the AVR32 is 192.168.3.135


Anyone knows of a fix, that can make the system keep transmitting messages while other messages are being transmitted in the other direction ?

Thank you.

Source code:

static portTASK_FUNCTION( shellTask, pvParameters )
{
   int sock, sock2, status, j;  
   struct sockaddr_in sockAddr;    

   sockAddr.sin_family      = AF_INET;
   sockAddr.sin_len          = sizeof(sockAddr);
   sockAddr.sin_port        = htons(6001);  
  sockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    sock     = lwip_socket (AF_INET, SOCK_STREAM, 0);
   lwip_bind   (sock, (struct sockaddr*) &sockAddr, sizeof(struct sockaddr_in));
   lwip_listen (sock, 1);  
   sock2 = lwip_accept (sock, (struct sockaddr*) &sockAddr, &status);
   while (1)  
  {
     lwip_write(sock2, "Hello\r", 6);
     for (j=0; j < 10000;j++);  
  }
}      



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html
_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: TCP Sockets Simultaneous Read andWrite

PeterAdamsen
This post was updated on .
Doing some more testing I have found that it isn't the Simultaneous Read and
Write that causes the pause.

It is the situation where the microcontroller received more than 7 messages
without being able to read them.

Sending more than 7 message to the loop below whinin 5 sec, will cause TCP
retransmissions, and large delays on PING's



   while (1)
   {
     lwip_read(sock2, str, 6);
     delay(5000);  // 5 sec
   }





--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: TCP Sockets Simultaneous Read andWrite

Sergio R. Caprile
In reply to this post by PeterAdamsen
I may be wrong since I know nothing on sockets on lwIP, but I think I
remember reading Simon saying you can't have two threads using the same
socket. (or at least that is what I think I see on how the post is
formatted)

What I do know:
Following your capture file is hard; you provide a whole net capture
with no clue whatsoever on what to see.
Who is the sender ? The HewlettPackard MAC machine ?
Who is the device ? Is it behind the Cisco MAC router ?
Your application is what ? Sending "Hello" every 2ms ?
However, I managed to see the pause you talk about

Did you try a known-good application to check if your port and your
driver are working as they should ?


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: TCP Sockets Simultaneous Read andWrite

PeterAdamsen
Sergio,

I do only have one thread running.

Sorry about the big capture, I have replaced it by a new filtered. Please
filter with: "ip.addr == 192.168.3.135".

My PC is 192.168.120.17, saying 0x0D ([ENTER]) once in a while.
My device is 192.168.3.135, saying "Hello" every 1-2 msec

There might be a Cisco router in between.


No, unfortunately I do not have a known-good application .....



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: TCP Sockets Simultaneous Read andWrite

Sergio R. Caprile
In reply to this post by Sergio R. Caprile
OK, now I see.
Well, you _should_ (read _must_) check your port and your driver.

Perhaps your simplest application can do, but you should try one of the
apps in the app subtree or in the contrib tree. Those have been tested
by many users.
I can't help you further, I'm nil on anything other than RAW API over
baremetal.

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users