Skip to content

Commit 17535b2

Browse files
author
fpr
committed
Fixed crash inside ChatServer & DhcpChatServer examples
Signed-off-by: fpr <[email protected]>
1 parent f3526cb commit 17535b2

File tree

4 files changed

+8
-46
lines changed

4 files changed

+8
-46
lines changed

libraries/NativeEthernet/examples/ChatServer/ChatServer.ino

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,6 @@
1212
by David A. Mellis
1313
modified 9 Apr 2012
1414
by Tom Igoe
15-
16-
Workaround:
17-
* If you can't send a message after the server has accepted the connection,
18-
reject the 26 first bytes.
19-
20-
if (client.available() > 0) {
21-
// read the bytes incoming from the client:
22-
char thisChar = client.read();
23-
if(n++ > 26) {
24-
// echo the bytes back to the client:
25-
server.write(thisChar);
26-
// echo the bytes to the server as well:
27-
Serial.write(thisChar);
28-
}
29-
}
30-
31-
32-
3315
*/
3416

3517
#include <NativeEthernet.h>

libraries/NativeEthernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,6 @@
1212
by Tom Igoe
1313
modified 02 Sept 2015
1414
by Arturo Guadalupi
15-
16-
Workaround:
17-
* If you can't send a message after the server has accepted the connection,
18-
reject the 26 first bytes.
19-
20-
if (client.available() > 0) {
21-
// read the bytes incoming from the client:
22-
char thisChar = client.read();
23-
if(n++ > 26) {
24-
// echo the bytes back to the client:
25-
server.write(thisChar);
26-
// echo the bytes to the server as well:
27-
Serial.write(thisChar);
28-
}
29-
}
30-
3115
*/
3216

3317
#include <NativeEthernet.h>

libraries/NativeEthernet/src/EthernetClient.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ size_t EthernetClient::write(const uint8_t *buf, size_t size) {
8888
return 0;
8989
}
9090

91+
/* If client not connected or accepted, it can't write because connection is
92+
not ready */
93+
if((_tcp_client->state != TCP_ACCEPTED) &&
94+
(_tcp_client->state != TCP_CONNECTED)) {
95+
return 0;
96+
}
97+
9198
if(ERR_OK != tcp_write(_tcp_client->pcb, buf, size, TCP_WRITE_FLAG_COPY)) {
9299
return 0;
93100
}
@@ -97,16 +104,7 @@ size_t EthernetClient::write(const uint8_t *buf, size_t size) {
97104
return 0;
98105
}
99106

100-
tcp_client_states tmp = _tcp_client->state;
101-
while(_tcp_client->state != TCP_SENT) {
102-
stm32_eth_scheduler();
103-
if(_tcp_client->state == TCP_CLOSING) {
104-
stop();
105-
return 0;
106-
}
107-
}
108-
109-
_tcp_client->state = tmp;
107+
stm32_eth_scheduler();
110108

111109
return size;
112110
}

libraries/NativeEthernet/src/utility/stm32_eth.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,6 @@ static err_t tcp_sent_callback(void *arg, struct tcp_pcb *tpcb, u16_t len)
916916

917917
if((tcp_arg != NULL) && (tcp_arg->pcb == tpcb))
918918
{
919-
/* still got pbufs to send */
920-
tcp_arg->state = TCP_SENT;
921919
return ERR_OK;
922920
}
923921

0 commit comments

Comments
 (0)