Skip to content
Closed
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
34 changes: 28 additions & 6 deletions servers.php
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,8 @@ function process_received($sock, $data, $n, $fromip, $fromport) {
}
}

socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec'=>1, 'usec'=>500000));
$timeout_ms = 500;
socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec'=>0, 'usec'=>$timeout_ms * 1000));

$name = isset($_GET['name']) ? $_GET['name'] : $host;

Expand All @@ -957,19 +958,40 @@ function process_received($sock, $data, $n, $fromip, $fromport) {
// $maxgap = 0;
// $last = gettimeofday(true);

while (!$done && $n = socket_recvfrom($sock, $data, 32767, 0, $fromip, $fromport)) {
// printf("socket_recvfrom: %d bytes received from %s:%d\n", $n, $fromip, $fromport);
$attempts = 1;
$max_attempts = 3;

if ($n != strlen($data)) {
error_log("Returned data length does not match string from $fromip:$fromport");
continue;
while (!$done) {
$n = socket_recvfrom($sock, $data, 32767, 0, $fromip, $fromport);

if ($n === false) {
if (count($servers) <= 1 && $attempts < $max_attempts) {
// Timeout with no data yet — re-send and try again
$attempts++;
if (isset($_GET['directory'])) {
send_request($sock, CLM_REQ_SERVER_LIST, $ip, $port);
} else {
send_ping_with_num_clients($sock, $ip, $port);
}
continue;
} elseif (count($servers) <= 1) {
error_log("servers.php: no response from $ip after $max_attempts attempts");
break;
} else {
break; // normal end-of-stream
}
}

// $now = gettimeofday(true);

// if ($now - $last > $maxgap) $maxgap = $now - $last;
// $last = $now;

if ($n != strlen($data)) {
error_log("Returned data length does not match string from $fromip:$fromport");
continue;
}

process_received($sock, $data, $n, $fromip, $fromport);
}

Expand Down