Skip to content

Commit 983d8af

Browse files
committed
Final changes for the Client part of issue 416, which actually include the corrent return values. This should have been in the previous commit, but I'm still getting my head round git.
1 parent 66eb085 commit 983d8af

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

libraries/Ethernet/Client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int Client::available() {
7777

7878
int Client::read() {
7979
uint8_t b;
80-
if ( recv(_sock, &b, 1) )
80+
if ( recv(_sock, &b, 1) > 0 )
8181
{
8282
// recv worked
8383
return b;

libraries/Ethernet/utility/socket.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,22 @@ uint16_t recv(SOCKET s, uint8_t *buf, uint16_t len)
148148
{
149149
// Check how much data is available
150150
uint16_t ret = W5100.getRXReceivedSize(s);
151-
if (ret > len)
151+
if ( ret == 0 )
152+
{
153+
// No data available.
154+
uint8_t status = W5100.readSnSR(s);
155+
if ( s == SnSR::LISTEN || s == SnSR::CLOSED || s == SnSR::CLOSE_WAIT )
156+
{
157+
// The remote end has closed its side of the connection, so this is the eof state
158+
ret = 0;
159+
}
160+
else
161+
{
162+
// The connection is still up, but there's no data waiting to be read
163+
ret = -1;
164+
}
165+
}
166+
else if (ret > len)
152167
{
153168
ret = len;
154169
}

0 commit comments

Comments
 (0)