Skip to content

Fixes to UDP so that it no longer has socket 0 hardcoded - all part of issue #436 #16

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

Merged
3 commits merged into from
Jan 5, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions libraries/Ethernet/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,25 @@ int Client::available() {

int Client::read() {
uint8_t b;
if (!available())
if ( recv(_sock, &b, 1) > 0 )
{
// recv worked
return b;
}
else
{
// No data available
return -1;
recv(_sock, &b, 1);
return b;
}
}

int Client::read(uint8_t *buf, size_t size) {
return recv(_sock, buf, size);
}

int Client::peek() {
uint8_t b;
// Unlike recv, peek doesn't check to see if there's any data available, so we must
if (!available())
return -1;
::peek(_sock, &b);
Expand Down
1 change: 1 addition & 0 deletions libraries/Ethernet/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Client : public Stream {
virtual void write(const uint8_t *buf, size_t size);
virtual int available();
virtual int read();
virtual int read(uint8_t *buf, size_t size);
virtual int peek();
virtual void flush();
void stop();
Expand Down
27 changes: 23 additions & 4 deletions libraries/Ethernet/utility/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,32 @@ uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len)
*/
uint16_t recv(SOCKET s, uint8_t *buf, uint16_t len)
{
uint16_t ret=0;
// Check how much data is available
uint16_t ret = W5100.getRXReceivedSize(s);
if ( ret == 0 )
{
// No data available.
uint8_t status = W5100.readSnSR(s);
if ( s == SnSR::LISTEN || s == SnSR::CLOSED || s == SnSR::CLOSE_WAIT )
{
// The remote end has closed its side of the connection, so this is the eof state
ret = 0;
}
else
{
// The connection is still up, but there's no data waiting to be read
ret = -1;
}
}
else if (ret > len)
{
ret = len;
}

if ( len > 0 )
if ( ret > 0 )
{
W5100.recv_data_processing(s, buf, len);
W5100.recv_data_processing(s, buf, ret);
W5100.execCmdSn(s, Sock_RECV);
ret = len;
}
return ret;
}
Expand Down