-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace Dazzle\ChannelZmq\Buffer; | ||
|
||
use Dazzle\Zmq\ZmqSocket; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
class Buffer | ||
{ | ||
/** | ||
* @var ZmqSocket | ||
*/ | ||
protected $socket; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
protected $messageBuffer; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $messageBufferSize; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $messageBufferMax; | ||
|
||
/** | ||
* @param ZmqSocket $socket | ||
* @param int $bufferSize | ||
*/ | ||
public function __construct(ZmqSocket $socket, $bufferSize = 0) | ||
{ | ||
$this->socket = $socket; | ||
$this->messageBuffer = []; | ||
$this->messageBufferSize = 0; | ||
$this->messageBufferMax = $bufferSize; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function __destruct() | ||
{ | ||
$this->erase(); | ||
unset($this->socket); | ||
} | ||
|
||
/** | ||
* @param string[] $frame | ||
* @return bool | ||
*/ | ||
public function add($frame) | ||
{ | ||
if ($this->messageBufferSize >= $this->messageBufferMax && $this->messageBufferMax > 0) | ||
{ | ||
return false; | ||
} | ||
|
||
$this->messageBuffer[] = $frame; | ||
$this->messageBufferSize++; | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function send() | ||
{ | ||
foreach ($this->messageBuffer as $message) | ||
{ | ||
$this->socket->send($message); | ||
} | ||
|
||
$this->messageBuffer = []; | ||
$this->messageBufferSize = 0; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function erase() | ||
{ | ||
$this->messageBuffer = []; | ||
$this->messageBufferSize = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Dazzle\ChannelZmq\Connection; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
class Connection | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @param string $id | ||
*/ | ||
public function __construct($id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
} |
Oops, something went wrong.