Optimised our sending and receiving of items
This commit is contained in:
@@ -17,7 +17,7 @@ final class SocketClient {
|
||||
private const LOGKEY = 'SC-';
|
||||
|
||||
// For deep debugging
|
||||
private bool $DEBUG = FALSE;
|
||||
private bool $DEBUG = TRUE;
|
||||
|
||||
private \Socket $connection;
|
||||
private string $address_local = '';
|
||||
@@ -214,7 +214,7 @@ final class SocketClient {
|
||||
$sent = $this->send(substr($this->tx_buf,0,self::TX_SIZE),0);
|
||||
|
||||
if ($this->DEBUG)
|
||||
Log::debug(sprintf('%s:- Sent [%d] chars [%s]',self::LOGKEY,$rc,Str::limit($this->tx_buf,15)));
|
||||
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);
|
||||
|
||||
@@ -356,7 +356,7 @@ final class SocketClient {
|
||||
$this->rx_buf .= $buf;
|
||||
|
||||
if ($this->DEBUG)
|
||||
Log::debug(sprintf('%s:- Added [%d] chars to the RX buffer',self::LOGKEY,strlen($buf)));
|
||||
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
|
||||
return $this->read($timeout,$len);
|
||||
@@ -404,13 +404,12 @@ final class SocketClient {
|
||||
/**
|
||||
* Send data to the client
|
||||
*
|
||||
* @param $message
|
||||
* @param string $message
|
||||
* @param int $timeout
|
||||
* @param null $length
|
||||
* @return false|int
|
||||
* @return int|false
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function send($message,int $timeout)
|
||||
public function send(string $message,int $timeout): int|false
|
||||
{
|
||||
if ($timeout AND (! $rc=$this->canSend($timeout)))
|
||||
return $rc;
|
||||
|
Reference in New Issue
Block a user