RAW TCP client gets terminated

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

RAW TCP client gets terminated

Jonas97
Hello,

Im running LwIP in NOSYS mode on a microcontroller.
Currently I have trouble implementing a RAW TCP Client.
I was able to run the HTTP Server including CGI/SSI and IPerf both as client
and server.
My Client gets a connection to a server(simple pyhton example server) and I
am able to send a few bytes(Hello World messages).
The problem is that after a few minutes the client stop working and even the
poll_cb stop getting called from LwIP.
It also doesn't matter if I send data while connected or do nothing after a
few minutes its just stop working.
I watched the connection via wireshark and there is nothing that would
indicate any kind of connection close or timeout.
The thing is that the HTTP Server still functions as usual so
sys_check_timeouts still gets called.
Also all callbacks where registered( arg, recv, sent, poll, err ) so LwIP
doesn't report anything back its just stop working.
I tried to look at the PCB but found nothing useful same with various debug
messages.

I put some data and source code below maybe someone can have a look or give
me a direction where to look.
Thanks for your help.

Jonas

The PCB data is a csv with tab as seperator didn't know a better way to copy
the data.
Wireshark data sending
<http://lwip.100.n7.nabble.com/file/t2366/data_Send.pcapng>  
Serial log data sending
<http://lwip.100.n7.nabble.com/file/t2366/data_send_log.txt>  
PCB data sending working.csv
<http://lwip.100.n7.nabble.com/file/t2366/pcb_ok_data_send.csv>  
PCB data sending no longer working.csv
<http://lwip.100.n7.nabble.com/file/t2366/pcb_not_ok_data_send.csv>  
Wireshark no data sending
<http://lwip.100.n7.nabble.com/file/t2366/no_data_send.pcapng>  
Serial log no data sending
<http://lwip.100.n7.nabble.com/file/t2366/no_data_send_log.txt>  
PCB no data working.csv
<http://lwip.100.n7.nabble.com/file/t2366/pcb_ok_no_data_send.csv>  
PCB no data no longer working.csv
<http://lwip.100.n7.nabble.com/file/t2366/pcb_not_ok_no_data_send.csv>  

Source code.c <http://lwip.100.n7.nabble.com/file/t2366/tcp_client.c>  




--
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: RAW TCP client gets terminated

Jonas97
Found the bug. My implementation of sys_now() wasn't rolling over as a 32 bit
variable.



--
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: RAW TCP client gets terminated

Hugh Reynolds
Jonas,
You may have fixed my bug too.
Where did you read what the expected behaviour of sys_now() is?
https://www.nongnu.org/lwip/2_0_x/group__sys__time.html perhaps isn't explicit.
Could you post your corrected code?

Regards

Hugh

-----Original Message-----
From: lwip-users <lwip-users-bounces+hugh=[hidden email]> On Behalf Of Jonas97
Sent: 16 March 2020 09:36
To: [hidden email]
Subject: Re: [lwip-users] RAW TCP client gets terminated

Found the bug. My implementation of sys_now() wasn't rolling over as a 32 bit
variable.



--
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


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


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

Re: RAW TCP client gets terminated

Jonas97
Hi Hugh,

I did not find any specific documentation on the way sys_now() should be
implemented.
After debugging I noticed that sys_check_timeouts was using following macro:

/* Check if timer's expiry time is greater than time and care about u32_t
wraparounds */
#define TIME_LESS_THAN(t, compare_to) ( (((u32_t)((t)-(compare_to))) >
LWIP_MAX_TIMEOUT) ? 1 : 0 )

So I suspect that the timer should run all the way to the unsigned 32 bit
wraparound point. This is only hit after 49 days so I didn't dig deeper as
my application doesn't run that long.

The problem was that the ms function for my microcontroller was wrapping
around after 71583 so instead of hitting 71584 it would start at zero again.

Below is my quick and dirty fix for this which might contain future bugs, is
gcc specific and also specific to the 71583 wrap around point. Feedback
always appreciated.

u32_t sys_now( void )
{
    static uint32_t ms = 0;
    static uint32_t lastMs = 0;

    uint32_t newMs = cpu_cy_2_ms( Get_sys_count(), sysclk_get_cpu_hz() );
    uint32_t diffMs;

    if( newMs < lastMs )
    {
        diffMs = ( newMs + 4294895712 ) - ( lastMs + 4294895712 );
        diffMs -= 4294895712;
    }
    else
    {
        diffMs = newMs - lastMs;
    }

    lastMs = newMs;
    ms += diffMs;

    return ms;
}
 



--
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: RAW TCP client gets terminated

Jonas97
In reply to this post by Hugh Reynolds
Hi Hugh,

I did not find any specific documentation on the way sys_now() should be
implemented.
After debugging I noticed that sys_check_timeouts was using following macro:

/* Check if timer's expiry time is greater than time and care about u32_t
wraparounds */
#define TIME_LESS_THAN(t, compare_to) ( (((u32_t)((t)-(compare_to))) >
LWIP_MAX_TIMEOUT) ? 1 : 0 )

So I suspect that the timer should run all the way to the unsigned 32 bit
wraparound point. This is only hit after 49 days so I didn't dig deeper as
my application doesn't run that long.

The problem was that the ms function for my microcontroller was wrapping
around after 71583 so instead of hitting 71584 it would start at zero again.

Below is my quick and dirty fix for this which might contain future bugs, is
gcc specific and also specific to the 71583 wrap around point. Feedback
always appreciated.

u32_t sys_now( void )
{
    static uint32_t ms = 0;
    static uint32_t lastMs = 0;

    uint32_t newMs = cpu_cy_2_ms( Get_sys_count(), sysclk_get_cpu_hz() );
    uint32_t diffMs;

    if( newMs < lastMs )
    {
        diffMs = ( newMs + 4294895712 ) - ( lastMs + 4294895712 );
        diffMs -= 4294895712;
    }
    else
    {
        diffMs = newMs - lastMs;
    }

    lastMs = newMs;
    ms += diffMs;

    return ms;
}
 



--
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: RAW TCP client gets terminated

Hugh Reynolds
In reply to this post by Jonas97
Jonas, many thanks.

Regards


-----Original Message-----
From: lwip-users <lwip-users-bounces+hugh=[hidden email]> On Behalf Of Jonas97
Sent: 16 March 2020 15:38
To: [hidden email]
Subject: Re: [lwip-users] RAW TCP client gets terminated

Hi Hugh,

I did not find any specific documentation on the way sys_now() should be
implemented.
After debugging I noticed that sys_check_timeouts was using following macro:

/* Check if timer's expiry time is greater than time and care about u32_t
wraparounds */
#define TIME_LESS_THAN(t, compare_to) ( (((u32_t)((t)-(compare_to))) >
LWIP_MAX_TIMEOUT) ? 1 : 0 )

So I suspect that the timer should run all the way to the unsigned 32 bit
wraparound point. This is only hit after 49 days so I didn't dig deeper as
my application doesn't run that long.

The problem was that the ms function for my microcontroller was wrapping
around after 71583 so instead of hitting 71584 it would start at zero again.

Below is my quick and dirty fix for this which might contain future bugs, is
gcc specific and also specific to the 71583 wrap around point. Feedback
always appreciated.

u32_t sys_now( void )
{
    static uint32_t ms = 0;
    static uint32_t lastMs = 0;

    uint32_t newMs = cpu_cy_2_ms( Get_sys_count(), sysclk_get_cpu_hz() );
    uint32_t diffMs;

    if( newMs < lastMs )
    {
        diffMs = ( newMs + 4294895712 ) - ( lastMs + 4294895712 );
        diffMs -= 4294895712;
    }
    else
    {
        diffMs = newMs - lastMs;
    }

    lastMs = newMs;
    ms += diffMs;

    return ms;
}
 



--
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


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


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

Re: RAW TCP client gets terminated

goldsimon@gmx.de
In reply to this post by Jonas97
Am 16.03.2020 um 17:42 schrieb Jonas97:
> Hi Hugh,
>
> I did not find any specific documentation on the way sys_now() should be
> implemented.

For things like this, improved documentation is always welcome. Plus it
should be easy to provide it for everyone...

> After debugging I noticed that sys_check_timeouts was using following macro:
>
> /* Check if timer's expiry time is greater than time and care about u32_t
> wraparounds */
> #define TIME_LESS_THAN(t, compare_to) ( (((u32_t)((t)-(compare_to))) >
> LWIP_MAX_TIMEOUT) ? 1 : 0 )
>
> So I suspect that the timer should run all the way to the unsigned 32 bit
> wraparound point. This is only hit after 49 days so I didn't dig deeper as
> my application doesn't run that long.

Yes, it should just continue. And yes, it's hard to test since this is a
purely port-provided function.

Regards,
Simon

>
> The problem was that the ms function for my microcontroller was wrapping
> around after 71583 so instead of hitting 71584 it would start at zero again.
>
> Below is my quick and dirty fix for this which might contain future bugs, is
> gcc specific and also specific to the 71583 wrap around point. Feedback
> always appreciated.
>
> u32_t sys_now( void )
> {
>     static uint32_t ms = 0;
>     static uint32_t lastMs = 0;
>
>     uint32_t newMs = cpu_cy_2_ms( Get_sys_count(), sysclk_get_cpu_hz() );
>     uint32_t diffMs;
>
>     if( newMs < lastMs )
>     {
>         diffMs = ( newMs + 4294895712 ) - ( lastMs + 4294895712 );
>         diffMs -= 4294895712;
>     }
>     else
>     {
>         diffMs = newMs - lastMs;
>     }
>
>     lastMs = newMs;
>     ms += diffMs;
>
>     return ms;
> }
>
>
>
>
> --
> 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
>


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