Skip to content

ClientContext.h: Remove delay and force output of queued data. #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

Chris--A
Copy link

This replaces a 5 second delay to an LWIP function tcp_output(). Rather than waiting for interrupts to handle sending, this will actively send the data.

I proposed this change on the esp8266 forum and it appears to solve a large latency issue:
http://www.esp8266.com/viewtopic.php?f=28&t=2672

This replaces a 5 second delay to an LWIP function `tcp_output()`. Rather than waiting for interrupts to handle sending, this will actively send the data.
@Chris--A Chris--A changed the title Remove delay and force output of queued data. ClientContext.h: Remove delay and force output of queued data. Apr 25, 2015
@igrr
Copy link
Member

igrr commented Apr 26, 2015

The reason this removes the latency is because we are no longer waiting for tcp_sent callback to fire. So essentially with this change we don't wait for confirmation that the packet has actually been delivered.
If this is the desired behavior, it's better to switch to UDP which has lower latency due to not bothering about packet delivery.

@igrr
Copy link
Member

igrr commented Apr 26, 2015

The execution flow looks like this:

  • in the send method _size_sent is set to the amount of data that we are attempting to send
  • the call to delay function causes a context switch — flow of execution is transferred to the scheduler
  • tcp task gets scheduled and the tcp_output function is called
  • when the packet is delivered, ClientContext::_sent method is called. It calculates the amount of data that is not yet delivered. If all the data has been delivered, it calls esp_schedule, which causes a context switch back into the sketch (to the _send_waiting = false; line in ClientContext::send).
  • if the packet is not delivered, the 5000-ms timer armed by the delay() function fires which also causes a context switch back into the sketch.

@Chris--A
Copy link
Author

Thank you for the explanation. I'll have to do some further research and see where we can save some more time.

@Chris--A Chris--A closed this Apr 26, 2015
@igrr
Copy link
Member

igrr commented Apr 26, 2015

using tcp_output() and delay() is one option that you may try.

@Chris--A
Copy link
Author

Yeah, I saw your post in the forum and was thinking the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants