\StreamTransmitter.php

Show: inherited

Wrapper for stream functionality.

This package provides data integrity to stream functionality, particularly useful for sockets.

PHP version 5

Author
Vasil Rangelov  
Category
Net  
Copyright
2011 Vasil Rangelov  
License
LGPL License 2.1  
Link
http://netrouteros.sourceforge.net/  
Package
PEAR2_Net_Transmitter  
Version
1.0.0a1  

\PEAR2\Net\Transmitter\StreamTransmitter

Package: PEAR2\Net\Transmitter

A stream transmitter.

This is a convinience wrapper for stream functionality. Used to ensure data integrity. Designed for sockets, but it has intentionally been made to accept any stream.

Children
\PEAR2\Net\Transmitter\SocketClientTransmitter
\PEAR2\Net\Transmitter\SocketServerConnectionTransmitter
See
\PEAR2\Net\Transmitter\Client  
Author
Vasil Rangelov  
Category
Net  
License
LGPL License 2.1  
Link
http://netrouteros.sourceforge.net/  

Constants

Constant  DIRECTION_BOTH = '|||'
Constant  DIRECTION_SEND = '<<<'
Constant  DIRECTION_RECEIVE = '>>>'

Properties

Propertyprotectedbool  $persist= ''

A flag that tells whether or not the stream is persistent.
Details
Type
bool
Propertyprotectedresource  $stream= ''

The stream to wrap around.
Details
Type
resource

Methods

methodpublic__construct( resource $stream ) : void

Wraps around the specified stream.

Parameters
Name Type Description
$stream resource

The stream to wrap around.

Details
See
\PEAR2\Net\Transmitter\isFresh()  
methodpublic__destruct( ) : void

Closes the opened stream, unless it's a persistent one.

methodpublicclose( ) : bool

Closes the opened stream, even if it is a persistent one.

Returns
Type Description
bool TRUE on success, FALSE on failure.
methodprotectedcreateException( string $message, int $code = 0 ) : \Exception

Creates a new exception.

Creates a new exception. Used by the rest of the functions in this class. Override in derived classes for custom exception handling.

Parameters
Name Type Description
$message string

The exception message.

$code int

The exception code.

Returns
Type Description
\Exception The exception to then be thrown.
methodpublicisAcceptingData( ) : bool

Checks whether the wrapped stream can be written to without a block.

Returns
Type Description
bool TRUE if the wrapped stream would not block on a write, FALSE otherwise.
methodpublicisAvailable( ) : bool

Checks whether the stream is available for operations.

Returns
Type Description
bool TRUE if the stream is available, FALSE otherwise.
methodpublicisDataAwaiting( ) : bool

Checks whether there is data to be read from the wrapped stream.

Returns
Type Description
bool TRUE if there is data to be read, FALSE otherwise.
methodpublicisFresh( ) : bool

Checks whether the wrapped stream is fresh.

Checks whether the wrapped stream is fresh. A stream is considered fresh if there hasn't been any activity on it. Particularly useful for detecting reused persistent connections.

Returns
Type Description
bool TRUE if the socket is fresh, FALSE otherwise.
methodpublicisStream( mixed $var ) : bool
static

Checks if a given variable is a stream resource.

Parameters
Name Type Description
$var mixed

The variable to check.

Returns
Type Description
bool TRUE on success, FALSE on failure.
methodpublicreceive( int $length, string $what = 'data' ) : string

Reads from the wrapped stream to receive.

Reads from the wrapped stream to receive content as a string.

Parameters
Name Type Description
$length int

The number of bytes to read.

$what string

Descriptive string about what is being received (used in exception messages).

Returns
Type Description
string The received content.
methodpublicreceiveStream( int $length, array $filters = array(, string $what = 'stream data' ) : resource

Reads from the wrapped stream to receive.

Reads from the wrapped stream to receive content as a stream.

Parameters
Name Type Description
$length int

The number of bytes to read.

$filters array

An array of filters to apply to the stream while receiving. Key is the filter name, value is an array of parameters for the filter.

$what string

Descriptive string about what is being received (used in exception messages).

Returns
Type Description
resource The received content.
methodpublicsend( string $string ) : int

Sends a string over the wrapped stream.

Parameters
Name Type Description
$string string

The string to send.

Returns
Type Description
int The number of bytes sent.
methodpublicsendStream( resource $stream ) : int

Sends a stream over the wrapped stream.

Parameters
Name Type Description
$stream resource

The stream to send.

Returns
Type Description
int The number of bytes sent.
methodpublicsetBuffer( int $size, string $direction = self::DIRECTION_BOTH ) : bool

Sets the size of a stream's buffer.

Parameters
Name Type Description
$size int

The desired size of the buffer, in bytes.

$direction string

The buffer of which direction to set. Valid values are the DIRECTION_* constants.

Returns
Type Description
bool TRUE on success, FALSE on failure.
methodpublicsetTimeout( int $seconds, int $microseconds = 0 ) : bool

Sets the timeout for the stream.

Parameters
Name Type Description
$seconds int

Timeout in seconds.

$microseconds int

Timeout in microseconds to be added to the seconds.

Returns
Type Description
bool TRUE on success, FALSE on failure.
Documentation was generated by DocBlox 0.14.1.