Change DEBUG to a static const

This commit is contained in:
2023-07-19 10:27:47 +10:00
parent ee03604de3
commit dcae06aad9
5 changed files with 48 additions and 48 deletions

View File

@@ -17,7 +17,7 @@ final class SocketClient {
private const LOGKEY = 'SC-';
// For deep debugging
private bool $DEBUG = TRUE;
private const DEBUG = FALSE;
private \Socket $connection;
private string $address_local = '';
@@ -162,11 +162,11 @@ final class SocketClient {
$num_bytes = strlen($data);
while ($num_bytes) {
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:- To add [%d] to the TX buffer',self::LOGKEY,$num_bytes));
if ($num_bytes > $this->tx_free) {
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:- TX buffer will be too full, draining...',self::LOGKEY));
do {
@@ -185,7 +185,7 @@ final class SocketClient {
}
}
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:= TX buffer has [%d] space left',self::LOGKEY,$this->tx_free));
}
@@ -198,7 +198,7 @@ final class SocketClient {
*/
public function buffer_flush(int $timeout): int
{
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:+ Emptying TX buffer with [%d] chars, and timeout [%d]',self::LOGKEY,strlen($this->tx_buf),$timeout));
$tm = $this->timer_set($timeout);
@@ -208,12 +208,12 @@ final class SocketClient {
$tv = $this->timer_rest($tm);
if (($rc=$this->canSend($tv)) > 0) {
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:- Chars to send [%d]',self::LOGKEY,strlen($this->tx_buf)));
$sent = $this->send(substr($this->tx_buf,0,self::TX_SIZE),0);
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:- Sent [%d] chars [%s]',self::LOGKEY,$sent,Str::limit($this->tx_buf,15)));
$this->tx_buf = substr($this->tx_buf,$sent);
@@ -291,7 +291,7 @@ final class SocketClient {
{
// We have data in our buffer
if ($this->rx_left >= $len) {
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:- Returning [%d] chars from the RX buffer',self::LOGKEY,$len));
$result = substr($this->rx_buf,0,$len);
@@ -329,7 +329,7 @@ final class SocketClient {
if ($recv === FALSE) {
// If we have something in the buffer, we'll send it
if ($this->rx_left) {
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:- Network read return an error, returning final [%d] chars from the RX buffer',self::LOGKEY,strlen($this->rx_buf)));
$result = $this->rx_buf;
@@ -355,7 +355,7 @@ final class SocketClient {
$this->rx_buf .= $buf;
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:- Added [%d] chars to the RX buffer',self::LOGKEY,strlen($buf)),['rx_buf'=>hex_dump($this->rx_buf)]);
// Loop again and return the data, now that it is in the RX buffer
@@ -384,7 +384,7 @@ final class SocketClient {
public function rx_purge(): void
{
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:+ Discarding [%d] chars from the RX buffer',self::LOGKEY,strlen($this->tx_buf)));
$this->rx_buf = '';
@@ -395,7 +395,7 @@ final class SocketClient {
*/
public function tx_purge(): void
{
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:+ Discarding [%d] chars from the TX buffer',self::LOGKEY,strlen($this->tx_buf)));
$this->tx_buf = '';
@@ -414,7 +414,7 @@ final class SocketClient {
if ($timeout AND (! $rc=$this->canSend($timeout)))
return $rc;
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:- Sending [%d] chars [%s]',self::LOGKEY,strlen($message),Str::limit($message,15)));
switch ($this->type) {
@@ -446,7 +446,7 @@ final class SocketClient {
if ($rc === FALSE)
throw new \Exception('Socket Error: '.socket_strerror(socket_last_error()));
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:= Socket select returned [%d] with timeout (%d)',self::LOGKEY,$rc,$timeout),['read'=>$read,'write'=>$write,'except'=>$except]);
return $rc;
@@ -480,7 +480,7 @@ final class SocketClient {
public function ttySelect(bool $read,bool $write, int $timeout): int
{
if ($this->rx_left) {
if ($this->DEBUG)
if (self::DEBUG)
Log::debug(sprintf('%s:= We still have [%d] chars in the RX buffer.',self::LOGKEY,$this->rx_left));
return 1;