Skip to content

Commit

Permalink
Added source
Browse files Browse the repository at this point in the history
  • Loading branch information
khelle committed Jun 25, 2017
1 parent 5e0b6d9 commit bb14b16
Show file tree
Hide file tree
Showing 5 changed files with 1,225 additions and 0 deletions.
92 changes: 92 additions & 0 deletions src/Channel-Zmq/Buffer/Buffer.php
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;
}
}
30 changes: 30 additions & 0 deletions src/Channel-Zmq/Connection/Connection.php
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;
}
}
Loading

0 comments on commit bb14b16

Please sign in to comment.