Skip to content

Commit ea6d07c

Browse files
marceloaqnomfalkvidd
authored andcommitted
Linux: Fix stability problem with ethernet (#1091)
- Fix a problem where mysgw stops working and consumes a lot of cpu. - Fix bug with tcp sockets where socket descriptor wasn't being freed.
1 parent 2175c99 commit ea6d07c

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

drivers/Linux/EthernetClient.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,8 @@ void EthernetClient::stop()
220220
gettimeofday(&startTime, NULL);
221221

222222
// wait up to a second for the connection to close
223-
uint8_t s;
224223
do {
225-
s = status();
224+
uint8_t s = status();
226225
if (s == ETHERNETCLIENT_W5100_CLOSED) {
227226
break; // exit the loop
228227
}
@@ -231,10 +230,8 @@ void EthernetClient::stop()
231230
} while (((curTime.tv_sec - startTime.tv_sec) * 1000000) + (curTime.tv_usec - startTime.tv_usec) <
232231
1000000);
233232

234-
// if it hasn't closed, close it forcefully
235-
if (s != ETHERNETCLIENT_W5100_CLOSED) {
236-
::close(_sock);
237-
}
233+
// free up the socket descriptor
234+
::close(_sock);
238235
_sock = -1;
239236
}
240237

drivers/Linux/EthernetServer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,11 @@ size_t EthernetServer::write(uint8_t b)
155155
size_t EthernetServer::write(const uint8_t *buffer, size_t size)
156156
{
157157
size_t n = 0;
158-
size_t i = 0;
159158

160-
while (i < clients.size()) {
159+
for (size_t i = 0; i < clients.size(); ++i) {
161160
EthernetClient client(clients[i]);
162161
if (client.status() == ETHERNETCLIENT_W5100_ESTABLISHED) {
163162
n += client.write(buffer, size);
164-
i++;
165163
}
166164
}
167165

0 commit comments

Comments
 (0)