Hoa central
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Hoa\Socket\Client Class Reference
Inheritance diagram for Hoa\Socket\Client:

Public Member Functions

 __construct ($socket, $timeout=30, $flag=self::CONNECT, $context=null)
 
 select ()
 
 consider (Connection $other)
 
 is (Connection $server)
 
 current ()
 
 isConnected ()
 
 isAsynchronous ()
 
 isPersistent ()
 

Public Attributes

const ASYNCHRONOUS = STREAM_CLIENT_ASYNC_CONNECT
 
const CONNECT = STREAM_CLIENT_CONNECT
 
const PERSISTENT = STREAM_CLIENT_PERSISTENT
 
const ENCRYPTION_SSLv2 = STREAM_CRYPTO_METHOD_SSLv2_CLIENT
 
const ENCRYPTION_SSLv3 = STREAM_CRYPTO_METHOD_SSLv3_CLIENT
 
const ENCRYPTION_SSLv23 = STREAM_CRYPTO_METHOD_SSLv23_CLIENT
 
const ENCRYPTION_TLS = STREAM_CRYPTO_METHOD_TLS_CLIENT
 

Protected Member Functions

_open ($streamName, Stream\Context $context=null)
 
 _close ()
 

Protected Attributes

 $_stack = []
 

Detailed Description

Class .

Established a client connection.

Definition at line 49 of file Client.php.

Constructor & Destructor Documentation

Hoa\Socket\Client::__construct (   $socket,
  $timeout = 30,
  $flag = self::CONNECT,
  $context = null 
)

Start a connection.

Parameters
string$socketSocket URI.
int$timeoutTimeout.
int$flagFlag, see the child::* constants.
string$contextContext ID (please, see the class).
Returns
void

Definition at line 119 of file Client.php.

124  {
125  parent::__construct($socket, $timeout, self::CONNECT & $flag, $context);
126 
127  return;
128  }

Member Function Documentation

Hoa\Socket\Client::_close ( )
protected

Close the current stream.

Returns
bool

Definition at line 185 of file Client.php.

186  {
187  if (true === $this->isPersistent()) {
188  return false;
189  }
190 
191  return @fclose($this->getStream());
192  }

Here is the call graph for this function:

& Hoa\Socket\Client::_open (   $streamName,
Stream\Context  $context = null 
)
protected

Open the stream and return the associated resource.

Parameters
string$streamNameSocket URI.
\Hoa\Stream\Context$contextContext.
Returns
resource
Exceptions

Definition at line 138 of file Client.php.

139  {
140  if (null === $context) {
141  $connection = @stream_socket_client(
142  $streamName,
143  $errno,
144  $errstr,
145  $this->getTimeout()/*,
146  $this->getFlag()*/
147  );
148  } else {
149  $connection = @stream_socket_client(
150  $streamName,
151  $errno,
152  $errstr,
153  $this->getTimeout()/*,
154  $this->getFlag(),
155  $context->getContext()*/
156  );
157  }
158 
159  if (false === $connection) {
160  if ($errno == 0) {
161  throw new Exception('Client cannot join %s.', 0, $streamName);
162  } else {
163  throw new Exception(
164  'Client returns an error (number %d): %s while trying ' .
165  'to join %s.',
166  1,
167  [$errno, $errstr, $streamName]
168  );
169  }
170  }
171 
172  $this->_stack[] = $connection;
173  $id = $this->getNodeId($connection);
174  $this->_node = dnew($this->getNodeName(), [$id, $connection, $this]);
175  $this->_nodes[$id] = $this->_node;
176 
177  return $connection;
178  }
Hoa\Socket\Client::consider ( Connection  $other)

Consider another client when selecting connection.

Parameters
\Hoa\Socket\Connection$otherOther client.
Returns

Definition at line 220 of file Client.php.

221  {
222  if (!($other instanceof self)) {
223  throw new Exception(
224  'Other client must be of type %s.',
225  2,
226  __CLASS__
227  );
228  }
229 
230  if (true === $other->isDisconnected()) {
231  $other->connect();
232  }
233 
234  $otherNode = $other->getCurrentNode();
235  $this->_stack[] = $otherNode->getSocket();
236  $this->_nodes[$otherNode->getId()] = $otherNode;
237 
238  return $this;
239  }
Hoa\Socket\Client::current ( )

Set and get the current selected connection.

Returns

Definition at line 257 of file Client.php.

258  {
259  $current = parent::_current();
260 
261  return $this->_node = $this->_nodes[$this->getNodeId($current)];
262  }
Hoa\Socket\Client::is ( Connection  $server)

Check if the current node belongs to a specific server.

Parameters
\Hoa\Socket\Connection$serverServer.
Returns
bool

Definition at line 247 of file Client.php.

248  {
249  return $this->getStream() === $server->getStream();
250  }
Hoa\Socket\Client::isAsynchronous ( )

Check if the connection is asynchronous or not.

Returns
bool

Definition at line 279 of file Client.php.

280  {
281  return (bool) ($this->getFlag() & self::ASYNCHRONOUS);
282  }
Hoa\Socket\Client::isConnected ( )

Check if the connection is connected or not.

Returns
bool

Definition at line 269 of file Client.php.

270  {
271  return (bool) ($this->getFlag() & self::CONNECT);
272  }
Hoa\Socket\Client::isPersistent ( )

Check if the connection is persistent or not.

Returns
bool

Definition at line 289 of file Client.php.

290  {
291  return (bool) ($this->getFlag() & self::PERSISTENT);
292  }

Here is the caller graph for this function:

Hoa\Socket\Client::select ( )

Select connections.

Returns

Definition at line 199 of file Client.php.

200  {
201  $read = $this->_stack;
202  $write = null;
203  $except = null;
204 
205  @stream_select($read, $write, $except, $this->getTimeout(), 0);
206 
207  foreach ($read as $socket) {
208  $this->_iterator[] = $socket;
209  }
210 
211  return $this;
212  }

Member Data Documentation

Hoa\Socket\Client::$_stack = []
protected

Definition at line 105 of file Client.php.

const Hoa\Socket\Client::ASYNCHRONOUS = STREAM_CLIENT_ASYNC_CONNECT

Open client socket asynchronously.

int

Definition at line 56 of file Client.php.

const Hoa\Socket\Client::CONNECT = STREAM_CLIENT_CONNECT

Open client socket connection.

int

Definition at line 63 of file Client.php.

const Hoa\Socket\Client::ENCRYPTION_SSLv2 = STREAM_CRYPTO_METHOD_SSLv2_CLIENT

Encryption: SSLv2.

int

Definition at line 77 of file Client.php.

const Hoa\Socket\Client::ENCRYPTION_SSLv23 = STREAM_CRYPTO_METHOD_SSLv23_CLIENT

Encryption: SSLv2.3.

int

Definition at line 91 of file Client.php.

const Hoa\Socket\Client::ENCRYPTION_SSLv3 = STREAM_CRYPTO_METHOD_SSLv3_CLIENT

Encryption: SSLv3.

int

Definition at line 84 of file Client.php.

const Hoa\Socket\Client::ENCRYPTION_TLS = STREAM_CRYPTO_METHOD_TLS_CLIENT

Encryption: TLS.

int

Definition at line 98 of file Client.php.

const Hoa\Socket\Client::PERSISTENT = STREAM_CLIENT_PERSISTENT

Client socket should remain persistent between page loads.

int

Definition at line 70 of file Client.php.


The documentation for this class was generated from the following file: