[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] prioritizing of active connections

From: Noam Weissman
Subject: Re: [lwip-users] prioritizing of active connections
Date: Sun, 25 Sep 2016 13:07:07 +0000



I was not near my working PC so I could not show any real code.

As far as I understand if you set 0 timeout as soon as you exit the call back

that it was set in it and return to the LwIP context your function will be called !


When you work with RAW API, everything is running under one task (if you have an OS)

Or in the same context. I am not sure how it works when you do not have an OS because

I did not work without it.


Any way the TCP stack is doing some housekeeping: responding to ACK, sending ACK, SYN etc…


Whenever you get a packet and the TCP stack call’s your recv callback the TCP stack is not running

until you exit from the callback. Once you exit from the callback the TCP stack returns to do its own

housekeeping… If you set a timer it starts to run after you exit the callback.

What can you do with the sys_timeout function… Lets assume that you get 300 bytes of data

and you need to process it… In recv callback you get the data, transfer it to a buffer and raise a flag to let

main handle the new data. Once main finished processing the data it can set another flag.


At the TCP stack you can set a timer at say 50ms… every 50ms it will call your timer callback function:


Define a function like this:

static void TcpDealyedSendHandler(void *arg)



  // does something


  IF data ready then process it and if needed, send it using tcp_write…


  ELSE start the timer again

   sys_timeout( 50, TcpDealyedSendHandler, NULL);







In your recv or any other callback set the timeout

    sys_timeout( 50, TcpDealyedSendHandler, NULL);



The above is just pseudo code to illustrate what I mean







From: lwip-users [mailto:lwip-users-bounces+address@hidden On Behalf Of Norbert Kleber
Sent: Sunday, September 25, 2016 2:15 PM
To: address@hidden
Subject: Re: [lwip-users] prioritizing of active connections




regarding the dirty trick I must admit I fear that it might cause a glitch thats right. I put it in eitherway as a proof of concept and running performance tests for evaluation of what might be possible. Since its a thesis i thought of  investigating the delay and the impact on the performance. For actual use it shouldn't be in the code!

Since I am messing with the TCP timer I suppose that it can cause earlier/unwanted retransmissions and connection timeouts. For my application both doesn't pose to much of a threat at this point.


Regarding the suggest function if i understand it right i just set it up within a callback function and if the


function is called and the localtime compared to the time when i set it up exceeds the intervall the function will be called. On that matter is it possible to assign 0 as intervall value so it will be called with the next sys_check_timeouts() ?


Also I want to say thank you for all your help.






Am 24.09.2016 um 14:58 schrieb Noam Weissman:



Doing some "dirty" trick will not help but cause other problems. IwIP can back-fire and

you will get unpredictable results. Problems that can be difficult to find.


sys_timeout is an LwIP function that runs inside the context of LwIP. Time interval is in milliseconds.


That means that if you set it to 100ms it will call your function (only once) when time elapses.


So instead of using the poll call back that is triggered at best every 0.5 seconds ... you can set your

own timeout function that will handle some house keeping at a faster rate. Do remember that if you

need it to periodically do something you need to set it again and again... until you finish the process.





From: lwip-users <lwip-users-bounces+address@hidden> on behalf of Norbert Kleber <address@hidden>
Sent: Saturday, September 24, 2016 11:20 AM
To: address@hidden
Subject: Re: [lwip-users] prioritizing of active connections


Hi Noam,


thank you for your suggestion. I guess I will start with an OS for the next project. For this one it's allready to late I am afraid (thesis due date next month). I didn't fully understand the explanation in the wiki regarding the sys_timeout(TMR_INTERVAL, function , NULL); function. Which timer triggers this function and how can i calculate the exact timing of the sys_timeout?

For now i found an quick and dirty approach which i can't recommand to anyone. I just call 2x tcp_tmr() directly after my computing work is done. This improves my performance. Where i needed 36 seconds for one run I now only need 16 seconds.





Am 23.09.2016 um 18:30 schrieb Noam Weissman:

Hi Norbert,


First of all I would suggest changing your design and use an OS. I am running FreeRTOS

on STM micro's for 6 years now and I do not see myself doing it any other way.


The STM32F4 is a strong micro with sufficient power to do much more then you do now.


If you run an OS there will be a small overhead but your system design will be much simpler

to menage.


If you use Socket API you can send data outside of the LwIP context. If you use RAW API

you cannot send data from outside of the LwIP context and must take that into consideration:


First option protect the code that is called from outside of the LwIP context. Either by using a

critical section (OS).... or using the poll call back.... or triggering LwIP own system_timer call-back:


    sys_timeout(TMR_INTERVAL, function , NULL);


The above is an LwIP internal timer handling. You pass the function you want (see prototype)

with or without parameters and it will be triggered when time expires.






From: lwip-users <lwip-users-bounces+address@hidden> on behalf of Norbert Kleber <address@hidden>
Sent: Friday, September 23, 2016 6:58 PM
To: address@hidden
Subject: [lwip-users] prioritizing of active connections


Hi evereyone,

I got some questions again.

I am using the lwIP on a STM32F4 mikrocontroller without OS. A client
will connect to the stack at two ports for transmission. First port will
be used for controlsignals and second for datatransmission. The whole
System works sequentially.

Firstly 1 package will be received on the ctrl connection afterwards we
receive many packages on the dataconnection. Now I was wondering that
the stack acknowlegded all data packages before he acknowledges the ctrl
package. Due to the operation of the µC I can tell that he received the
package right away and ofcause i use the acknowledgement function in the
receive function.  But somehow it is severly delayed approx. 200ms but
the later received data packages all get acknowledged right away.

Does the stack some prioritizing between open connections? Or is it due
to the Ctrl Package being quite short?

Also I am doing some computational work outside of the callback
functions and want to transmit some of the results asap over the ctrl
connection. Is there a way to do that without waiting for the polling
function? Or is there a way to trigger the polling function somehow for
a instant call? Also it seemed like i can't use tcp_write if i am
outside of a callback function (i was storing the pointer to the pcb in
a global variable).



lwip-users mailing list


Welcome to the lwip-users mailing list. Use it to ask questions, share your experience and discuss new ideas. To see the collection of prior postings to the list ...


lwip-users mailing list


lwip-users mailing list


reply via email to

[Prev in Thread] Current Thread [Next in Thread]