Skip to content

Providing a more fair servicing of multiple clients by not picking lowest numbered socket in available() #4463

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions libraries/Ethernet/src/EthernetServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ EthernetClient EthernetServer::available()
{
accept();

for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
EthernetClient client(sock);
if (EthernetClass::_server_port[sock] == _port) {
for (int i = 0; i < MAX_SOCK_NUM; i++) {
// increment _lastReturnedSocket to avoid returning the same socket again
_lastReturnedSocket = (_lastReturnedSocket + 1) % MAX_SOCK_NUM;

EthernetClient client(_lastReturnedSocket);
if (EthernetClass::_server_port[_lastReturnedSocket] == _port) {
uint8_t s = client.status();
if (s == SnSR::ESTABLISHED || s == SnSR::CLOSE_WAIT) {
if (client.available()) {
// XXX: don't always pick the lowest numbered socket.
// doesn't always pick the lowest numbered socket, because of
// _lastReturnedSocket + 1 at the beginning
return client;
}
}
Expand Down
1 change: 1 addition & 0 deletions libraries/Ethernet/src/EthernetServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public Server {
private:
uint16_t _port;
void accept();
int _lastReturnedSocket = -1;
public:
EthernetServer(uint16_t);
EthernetClient available();
Expand Down