-
Notifications
You must be signed in to change notification settings - Fork 13.3k
ClientContext (tcp) updates #5089
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
Changes from 1 commit
6c64759
746ec81
53c9222
6de50d4
2dd152d
f87602a
6be4b6f
8f7fb1e
c0bea2b
d00ac35
53931c5
81ec0f4
fbf1dd1
b4a918f
c14eeef
238610e
d0036a1
e4c187b
d31d6f2
5cf60b6
a058506
a7a5959
d06cac2
e8c659e
f271b2a
7f57694
888bdb8
c59a91f
3c54c9e
8414e17
4d62879
826b8b5
3fa6a97
72b59d9
7752c98
c160d17
db8fe6c
8bb444d
33dee32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ class ClientContext | |
| { | ||
| public: | ||
| ClientContext(tcp_pcb* pcb, discard_cb_t discard_cb, void* discard_cb_arg) : | ||
| _pcb(pcb), _rx_buf(0), _rx_buf_offset(0), _discard_cb(discard_cb), _discard_cb_arg(discard_cb_arg), _refcnt(0), _next(0) | ||
| _pcb(pcb), _rx_buf(0), _rx_buf_offset(0), _discard_cb(discard_cb), _discard_cb_arg(discard_cb_arg), _refcnt(0), _next(0), _sync(WiFiClient::getDefaultSync()) | ||
|
||
| { | ||
| tcp_setprio(pcb, TCP_PRIO_MIN); | ||
| tcp_arg(pcb, this); | ||
|
|
@@ -44,7 +44,7 @@ class ClientContext | |
| tcp_err(pcb, &_s_error); | ||
| tcp_poll(pcb, &_s_poll, 1); | ||
|
|
||
| // not enabled by default for 2.4.0 | ||
| // keep-alive not enabled by default | ||
| //keepAlive(); | ||
| } | ||
|
|
||
|
|
@@ -159,7 +159,7 @@ class ClientContext | |
| } | ||
| } | ||
|
|
||
| bool getNoDelay() | ||
| bool getNoDelay() const | ||
| { | ||
| if(!_pcb) { | ||
| return false; | ||
|
|
@@ -172,12 +172,12 @@ class ClientContext | |
| _timeout_ms = timeout_ms; | ||
| } | ||
|
|
||
| int getTimeout() | ||
| int getTimeout() const | ||
| { | ||
| return _timeout_ms; | ||
| } | ||
|
|
||
| uint32_t getRemoteAddress() | ||
| uint32_t getRemoteAddress() const | ||
| { | ||
| if(!_pcb) { | ||
| return 0; | ||
|
|
@@ -186,7 +186,7 @@ class ClientContext | |
| return _pcb->remote_ip.addr; | ||
| } | ||
|
|
||
| uint16_t getRemotePort() | ||
| uint16_t getRemotePort() const | ||
| { | ||
| if(!_pcb) { | ||
| return 0; | ||
|
|
@@ -195,7 +195,7 @@ class ClientContext | |
| return _pcb->remote_port; | ||
| } | ||
|
|
||
| uint32_t getLocalAddress() | ||
| uint32_t getLocalAddress() const | ||
| { | ||
| if(!_pcb) { | ||
| return 0; | ||
|
|
@@ -204,7 +204,7 @@ class ClientContext | |
| return _pcb->local_ip.addr; | ||
| } | ||
|
|
||
| uint16_t getLocalPort() | ||
| uint16_t getLocalPort() const | ||
| { | ||
| if(!_pcb) { | ||
| return 0; | ||
|
|
@@ -257,7 +257,7 @@ class ClientContext | |
| return size_read; | ||
| } | ||
|
|
||
| char peek() | ||
| char peek() const | ||
| { | ||
| if(!_rx_buf) { | ||
| return 0; | ||
|
|
@@ -266,7 +266,7 @@ class ClientContext | |
| return reinterpret_cast<char*>(_rx_buf->payload)[_rx_buf_offset]; | ||
| } | ||
|
|
||
| size_t peekBytes(char *dst, size_t size) | ||
| size_t peekBytes(char *dst, size_t size) const | ||
| { | ||
| if(!_rx_buf) { | ||
| return 0; | ||
|
|
@@ -307,7 +307,7 @@ class ClientContext | |
| int tries = 1+ WAIT_TRIES_MS; | ||
|
|
||
| while (state() == ESTABLISHED && tcp_sndbuf(_pcb) != TCP_SND_BUF && --tries) { | ||
| _write_some(); | ||
| //_write_some(); | ||
| delay(1); // esp_ schedule+yield | ||
| } | ||
| } | ||
|
|
@@ -321,7 +321,6 @@ class ClientContext | |
| return _pcb->state; | ||
| } | ||
|
|
||
|
|
||
| size_t write(const uint8_t* data, size_t size) | ||
| { | ||
| if (!_pcb) { | ||
|
|
@@ -379,6 +378,16 @@ class ClientContext | |
| return isKeepAliveEnabled()? _pcb->keep_cnt: 0; | ||
| } | ||
|
|
||
| bool getSync () const | ||
| { | ||
| return _sync; | ||
| } | ||
|
|
||
| void setSync (bool sync) | ||
| { | ||
| _sync = sync; | ||
| } | ||
|
|
||
| protected: | ||
|
|
||
| bool _is_timeout() | ||
|
|
@@ -418,6 +427,10 @@ class ClientContext | |
| esp_yield(); | ||
| } while(true); | ||
| _send_waiting = 0; | ||
|
|
||
| if (_sync) | ||
| wait_until_sent(); | ||
|
|
||
| return _written; | ||
| } | ||
|
|
||
|
|
@@ -442,11 +455,9 @@ class ClientContext | |
| // PUSH is for peer, telling to give to user app as soon as received | ||
| // PUSH may be set when sender has finished sending a meaningful data block | ||
| // Nagle is for delaying local stack, to send less and bigger packets | ||
| uint8_t flags = TCP_WRITE_FLAG_COPY; | ||
| if (!tcp_nagle_disabled(_pcb)) | ||
| // nagle enabled, delayed, buffering, bigger packets | ||
| // (When should we use PUSH?) | ||
| flags |= TCP_WRITE_FLAG_MORE; | ||
| uint8_t flags = TCP_WRITE_FLAG_MORE; // do not tcp-PuSH (XXX always?) | ||
| if (!_sync) | ||
| flags |= TCP_WRITE_FLAG_COPY; | ||
| err_t err = tcp_write(_pcb, buf, next_chunk_size, flags); | ||
| DEBUGV(":wrc %d %d %d\r\n", next_chunk_size, will_send, (int)err); | ||
|
||
| if (err == ERR_OK) { | ||
|
|
@@ -460,10 +471,12 @@ class ClientContext | |
| } | ||
| } | ||
|
|
||
| if (has_written && tcp_nagle_disabled(_pcb)) | ||
| if (has_written && (_sync || tcp_nagle_disabled(_pcb))) | ||
| { | ||
| // handle nagle manually because of TCP_WRITE_FLAG_MORE | ||
| // lwIP's tcp_output: "Find out what we can send and send it" | ||
| tcp_output(_pcb); | ||
| } | ||
|
|
||
| return has_written; | ||
| } | ||
|
|
@@ -472,7 +485,7 @@ class ClientContext | |
| { | ||
| // lwIP needs feeding | ||
| _write_some(); | ||
|
|
||
| if (_send_waiting == 1) { | ||
| _send_waiting--; | ||
| } | ||
|
|
@@ -596,14 +609,15 @@ class ClientContext | |
|
|
||
| DataSource* _datasource = nullptr; | ||
| size_t _written = 0; | ||
| //size_t _write_chunk_size = 256; | ||
| uint32_t _timeout_ms = 5000; | ||
| uint32_t _op_start_time = 0; | ||
| uint8_t _send_waiting = 0; | ||
| uint8_t _connect_pending = 0; | ||
|
|
||
| int8_t _refcnt; | ||
| ClientContext* _next; | ||
|
|
||
| bool _sync; | ||
| }; | ||
|
|
||
| #endif//CLIENTCONTEXT_H | ||
Uh oh!
There was an error while loading. Please reload this page.