\StreamTransmitter.php
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
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
Properties
Methods

__construct(
resource $stream
)
:
voidWraps around the specified stream.
| Name | Type | Description |
|---|---|---|
| $stream | resource | The stream to wrap around. |
- See
- \PEAR2\Net\Transmitter\isFresh()

close(
)
:
boolCloses the opened stream, even if it is a persistent one.
| Type | Description |
|---|---|
| bool | TRUE on success, FALSE on failure. |

createException(
string $message, int $code
=
0
)
:
\ExceptionCreates 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.
| Name | Type | Description |
|---|---|---|
| $message | string | The exception message. |
| $code | int | The exception code. |
| Type | Description |
|---|---|
| \Exception | The exception to then be thrown. |

isAcceptingData(
)
:
boolChecks whether the wrapped stream can be written to without a block.
| Type | Description |
|---|---|
| bool | TRUE if the wrapped stream would not block on a write, FALSE otherwise. |

isAvailable(
)
:
boolChecks whether the stream is available for operations.
| Type | Description |
|---|---|
| bool | TRUE if the stream is available, FALSE otherwise. |

isDataAwaiting(
)
:
boolChecks whether there is data to be read from the wrapped stream.
| Type | Description |
|---|---|
| bool | TRUE if there is data to be read, FALSE otherwise. |

isFresh(
)
:
boolChecks 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.
| Type | Description |
|---|---|
| bool | TRUE if the socket is fresh, FALSE otherwise. |

isStream(
mixed $var
)
:
boolChecks if a given variable is a stream resource.
| Name | Type | Description |
|---|---|---|
| $var | mixed | The variable to check. |
| Type | Description |
|---|---|
| bool | TRUE on success, FALSE on failure. |

receive(
int $length, string $what
=
'data'
)
:
stringReads from the wrapped stream to receive.
Reads from the wrapped stream to receive content as a string.
| Name | Type | Description |
|---|---|---|
| $length | int | The number of bytes to read. |
| $what | string | Descriptive string about what is being received (used in exception messages). |
| Type | Description |
|---|---|
| string | The received content. |

receiveStream(
int $length, array $filters
=
array(, string $what
=
'stream data'
)
:
resourceReads from the wrapped stream to receive.
Reads from the wrapped stream to receive content as a stream.
| 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). |
| Type | Description |
|---|---|
| resource | The received content. |

send(
string $string
)
:
intSends a string over the wrapped stream.
| Name | Type | Description |
|---|---|---|
| $string | string | The string to send. |
| Type | Description |
|---|---|
| int | The number of bytes sent. |

sendStream(
resource $stream
)
:
intSends a stream over the wrapped stream.
| Name | Type | Description |
|---|---|---|
| $stream | resource | The stream to send. |
| Type | Description |
|---|---|
| int | The number of bytes sent. |

setBuffer(
int $size, string $direction
=
self::DIRECTION_BOTH
)
:
boolSets the size of a stream's buffer.
| 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. |
| Type | Description |
|---|---|
| bool | TRUE on success, FALSE on failure. |