Commit 9fac290
committed
Added close_abort() function to WiFiClient
This branch adds a close_abort() method to the WiFiClient class.
How it works, what it does:
Calling `close_abort()` will close and abort the client connection it
is invoked on and, as a result, free its resources (i.e. memory).
**WARNING:** aborting connections without a good reason violates the
TCP protocol, because a closed connection would normally need to
spend some time in `TIME_WAIT` state before its resources are freed.
Usage example:
WiFiClient client; // set up a client
{ /* do things with your client */ }
client.stop_abort() // when you're done,abort the
// connection if you must
Why it's useful:
1. Give programmers a way to shut down connections immediately if
need be. The underlying `tcp.c` file has an abort function, but
this has not been directly accessible via the `WiFiClient`
class until now.
2. There are a number of reported issues for the repository
addressing the heap corruption that can result from trying to
retain too many connections in `TIME_WAIT` state (most notably:
esp8266#230, esp8266#1070, esp8266#1923). Although the warning above holds, there may be
circumstances where this isn't very important. For example an ESP8266
running in AP mode hosting a page, which requests a new
connection every second via an AJAX script to monitor
a sensor/button/etc. continusously.
Currently existing alternative approach:
When building a project, defining the
`-D MEMP_NUM_TCP_PCB_TIME_WAIT=5`compiler directive will limit the
maximum number of clients allowed to stay in TIME_WAIT state. `5` is
the default, lower it as necessary. See reference
[here](https://github.com/esp8266/Arduino/blob/master/tools/sdk/lwip/include/lwipopts.h#L263)
Thanks:
Thank you to @me-no-dev, @everslick and @Palatis for bringing the `
MEMP_NUM_TCP_PCB_TIME_WAIT` option to my attention.1 parent 7b32e6a commit 9fac290
File tree
3 files changed
+46
-0
lines changed- libraries/ESP8266WiFi/src
- include
3 files changed
+46
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
272 | 281 | | |
273 | 282 | | |
274 | 283 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
89 | 110 | | |
90 | 111 | | |
91 | 112 | | |
| |||
123 | 144 | | |
124 | 145 | | |
125 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
126 | 162 | | |
127 | 163 | | |
128 | 164 | | |
| |||
0 commit comments