Skip to content

Commit 4694939

Browse files
committed
Run housekeeping after the given timeout period
Also fixes issue #10
1 parent d04e3da commit 4694939

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/main/php/peer/server/Server.class.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,25 @@ public function service() {
133133
// Build array of sockets that we want to check for data. If one of them
134134
// has disconnected in the meantime, notify the listeners (socket will be
135135
// already invalid at that time) and remove it from the clients list.
136-
$read= [$this->socket->getHandle()];
137-
$currentTime= time();
138-
foreach ($handles as $h => $handle) {
139-
if (!$handle->isConnected()) {
140-
$this->protocol->handleDisconnect($handle);
141-
unset($handles[$h]);
142-
unset($lastAction[$h]);
143-
} else if ($currentTime - $lastAction[$h] > $handle->getTimeout()) {
144-
$this->protocol->handleError($handle, new \peer\SocketTimeoutException('Timed out', $handle->getTimeout()));
145-
$handle->close();
146-
unset($handles[$h]);
147-
unset($lastAction[$h]);
148-
} else {
149-
$read[]= $handle->getHandle();
136+
do {
137+
$read= [$this->socket->getHandle()];
138+
$currentTime= time();
139+
foreach ($handles as $h => $handle) {
140+
if (!$handle->isConnected()) {
141+
$this->protocol->handleDisconnect($handle);
142+
unset($handles[$h]);
143+
unset($lastAction[$h]);
144+
} else if ($currentTime - $lastAction[$h] > $handle->getTimeout()) {
145+
$this->protocol->handleError($handle, new \peer\SocketTimeoutException('Timed out', $handle->getTimeout()));
146+
$handle->close();
147+
unset($handles[$h]);
148+
unset($lastAction[$h]);
149+
} else {
150+
$read[]= $handle->getHandle();
151+
}
150152
}
151-
}
152153

153-
// Check to see if there are sockets with data on it.
154-
do {
154+
// Check to see if there are sockets with data on it.
155155
$n= $sockets->select0($read, $null, $null, $timeout);
156156
} while (0 === $n);
157157

0 commit comments

Comments
 (0)