Skip to content

Commit

Permalink
Make most errors non-fatal and log ip:port
Browse files Browse the repository at this point in the history
  • Loading branch information
softins committed Mar 13, 2023
1 parent 0e3ba7d commit 4cde755
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions servers.php
Expand Up @@ -557,7 +557,7 @@ function send_audio($sock, $size, $ip, $port) {
$n = socket_sendto($sock, $data, strlen($data), 0, $ip, $port);

if ($n === false) {
die("Send error: ".socket_strerror(socket_last_error()));
error_log("Send error to $ip:$port: ".socket_strerror(socket_last_error()));
}
}

Expand All @@ -578,7 +578,7 @@ function send_ackn($sock, $cnt, $id, $ip, $port) {
$n = socket_sendto($sock, $data, strlen($data), 0, $ip, $port);

if ($n === false) {
die("Send error: ".socket_strerror(socket_last_error()));
error_log("Send error to $ip:$port: ".socket_strerror(socket_last_error()));
}
}

Expand All @@ -598,7 +598,7 @@ function send_request($sock, $id, $ip, $port) {
$n = socket_sendto($sock, $data, strlen($data), 0, $ip, $port);

if ($n === false) {
die("Send error: ".socket_strerror(socket_last_error()));
error_log("Send error to $ip:$port: ".socket_strerror(socket_last_error()));
}
}

Expand All @@ -622,7 +622,7 @@ function send_ping_with_num_clients($sock, $ip, $port) {
$n = socket_sendto($sock, $data, strlen($data), 0, $ip, $port);

if ($n === false) {
die("Send error: ".socket_strerror(socket_last_error()));
error_log("Send error to $ip:$port: ".socket_strerror(socket_last_error()));
}
}

Expand All @@ -645,14 +645,16 @@ function process_received($sock, $data, $n, $fromip, $fromport) {
unset($crc);

if ($recvcrc != $calccrc) {
die("CRC mismatch in received message");
error_log("CRC mismatch in received message from $fromip:$fromport");
return;
}

$r = unpack("vtag/vid/Ccnt/vlen", substr($data, 0, 7));
// print_r($r);

if ($r['len']+9 != $n) {
die("Malformed packet - length mismatch");
error_log("Malformed packet - length mismatch from $fromip:$fromport");
return;
}

// print("ID=".$r['id']."\n");
Expand Down Expand Up @@ -939,7 +941,8 @@ function process_received($sock, $data, $n, $fromip, $fromport) {
// printf("socket_recvfrom: %d bytes received from %s:%d\n", $n, $fromip, $fromport);

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

// $now = gettimeofday(true);
Expand Down

0 comments on commit 4cde755

Please sign in to comment.