Skip to content

Commit 91abc01

Browse files
committed
EthernetClient - flush() does uip_poll_conn. my strong buffering removed
It turned out, it is better not to wait for the buffer to fill, but to send the packet right after ACK for the previous packet. flush() is implemented to send a packet immediately if there is no outstanding packet.
1 parent 35c738c commit 91abc01

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ The modernization includes:
55
* Ethernet 2.0 library functions
66
* support of many Arduino architectures by using the SPI library
77
* SPI transactions to share the SPI bus with devices with different communication settings
8-
* heavy buffering of sent TCP data in ENC with flush() function to send the last buffer
8+
* SPI communication at 20 MHz if the MCU supports it, else on the maximum supported by the MCU
9+
* client.flush() to send the packet immediately
910

1011
[The documentation of Arduino Ethernet library](https://www.arduino.cc/en/Reference/Ethernet) applies for class and functions descriptions.
1112

src/EthernetClient.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ UIPClient::stop()
115115
}
116116
else
117117
{
118+
flush();
118119
data->state |= UIP_CLIENT_CLOSE;
119120
}
120121
#ifdef UIPETHERNET_DEBUG_CLIENT
@@ -205,6 +206,8 @@ UIPClient::write(const uint8_t *buf, size_t size)
205206
u->out_pos+=written;
206207
if (remain > 0)
207208
{
209+
if (p == 0) // block 0 just filled, start sending immediately
210+
flush();
208211
if (p == UIP_SOCKET_NUMPACKETS-1)
209212
{
210213
#if UIP_WRITE_TIMEOUT > 0
@@ -240,8 +243,21 @@ UIPClient::availableForWrite()
240243
void
241244
UIPClient::flush()
242245
{
246+
UIPEthernetClass::tick();
247+
243248
if (data && data->packets_out[0] != NOBLOCK)
244-
data->state |= UIP_CLIENT_FLUSH;
249+
{
250+
struct uip_conn* conn = &uip_conns[data->conn_index];
251+
if (!uip_outstanding(conn))
252+
{
253+
uip_poll_conn(conn);
254+
if (uip_len > 0)
255+
{
256+
uip_arp_out();
257+
UIPEthernetClass::network_send();
258+
}
259+
}
260+
}
245261
}
246262

247263
int
@@ -439,8 +455,6 @@ uipclient_appcall(void)
439455
Serial.println(F("UIPClient uip_acked"));
440456
#endif
441457
UIPClient::_eatBlock(u->packets_out);
442-
if (u->packets_out[0] == NOBLOCK)
443-
u->state &= ~UIP_CLIENT_FLUSH;
444458
goto send;
445459
}
446460
if (uip_poll() || uip_rexmit())
@@ -453,14 +467,12 @@ uipclient_appcall(void)
453467
{
454468
if (u->packets_out[1] == NOBLOCK)
455469
{
456-
if ((u->state & UIP_CLIENT_FLUSH) || (u->state & UIP_CLIENT_CLOSE)) {
457470
send_len = u->out_pos;
458471
if (send_len > 0)
459472
{
460473
Enc28J60Network::resizeBlock(u->packets_out[0],0,send_len);
461474
}
462475
}
463-
}
464476
else
465477
send_len = Enc28J60Network::blockSize(u->packets_out[0]);
466478
if (send_len > 0)

src/EthernetClient.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ extern "C" {
3434
#define UIP_CLIENT_REMOTECLOSED 0x04
3535
#define UIP_CLIENT_RESTART 0x08
3636
#define UIP_CLIENT_ACCEPTED 0x10
37-
#define UIP_CLIENT_FLUSH 0x20
3837

3938
typedef struct {
4039
uint8_t conn_index;

0 commit comments

Comments
 (0)