File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -52,17 +52,22 @@ EthernetClient EthernetServer::available()
52
52
{
53
53
accept ();
54
54
55
- for (int sock = 0 ; sock < MAX_SOCK_NUM; sock++) {
56
- EthernetClient client (sock);
57
- if (EthernetClass::_server_port[sock] == _port) {
55
+ // increment _sock to avoid returning the same socket again
56
+ _sock = (_sock + 1 ) % MAX_SOCK_NUM;
57
+
58
+ for (int i = 0 ; i < MAX_SOCK_NUM; i++) {
59
+ EthernetClient client (_sock);
60
+ if (EthernetClass::_server_port[_sock] == _port) {
58
61
uint8_t s = client.status ();
59
62
if (s == SnSR::ESTABLISHED || s == SnSR::CLOSE_WAIT) {
60
63
if (client.available ()) {
61
- // XXX: don't always pick the lowest numbered socket.
64
+ // doesn't always pick the lowest numbered socket, because of _sock +
65
+ // 1 at the beginning
62
66
return client;
63
67
}
64
68
}
65
69
}
70
+ _sock = (_sock + 1 ) % MAX_SOCK_NUM;
66
71
}
67
72
68
73
return EthernetClient (MAX_SOCK_NUM);
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ public Server {
10
10
private:
11
11
uint16_t _port;
12
12
void accept ();
13
+ int _sock = -1 ;
13
14
public:
14
15
EthernetServer (uint16_t );
15
16
EthernetClient available ();
You can’t perform that action at this time.
0 commit comments