-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added NetworkStream, plus some forward compatibility stuff.
- Loading branch information
Showing
9 changed files
with
147 additions
and
48 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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
Lots of reorganization and initial test suite. | ||
|
||
* Added test suite with nearly complete code coverage. | ||
* Added FilterCollection, in turn allowing for the same filter to be applied more than once. | ||
* Renamed all "Socket*Transmitter" classes to "Tcp*". | ||
* Added test suite with nearly complete code coverage. Remaining coverage is due to forward compatibility issues. | ||
* Added FilterCollection, in turn allowing for the same filter to be applied more than once. | ||
* Added NetworkStream, and made Tpc* classes inherit from it. This new class contains a new method called shutdown(). | ||
* IPv6 addresses must now be written literally, without the surrounding "[" and "]". | ||
* TcpServerConnection can now accept IPv6 connections. | ||
* Merged sendStream() into send(). | ||
* Removed redundant error variables in TcpServerConnection. | ||
* Removed the TcpServerConnection::isServer() function (can't tell apart server and client). |
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,83 @@ | ||
<?php | ||
|
||
/** | ||
* ~~summary~~ | ||
* | ||
* ~~description~~ | ||
* | ||
* PHP version 5 | ||
* | ||
* @category Net | ||
* @package PEAR2_Net_Transmitter | ||
* @author Vasil Rangelov <[email protected]> | ||
* @copyright 2011 Vasil Rangelov | ||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 | ||
* @version SVN: $WCREV$ | ||
* @link http://pear2.php.net/PEAR2_Net_Transmitter | ||
*/ | ||
/** | ||
* The namespace declaration. | ||
*/ | ||
namespace PEAR2\Net\Transmitter; | ||
|
||
/** | ||
* A network transmitter. | ||
* | ||
* This is a convinience wrapper for network streams. Used to ensure data | ||
* integrity. | ||
* | ||
* @category Net | ||
* @package PEAR2_Net_Transmitter | ||
* @author Vasil Rangelov <[email protected]> | ||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 | ||
* @link http://pear2.php.net/PEAR2_Net_Transmitter | ||
*/ | ||
class NetworkStream extends Stream | ||
{ | ||
|
||
/** | ||
* Checks whether there is data to be read from the socket. | ||
* | ||
* @return bool TRUE if there is data to be read, FALSE otherwise. | ||
*/ | ||
public function isDataAwaiting() | ||
{ | ||
if (parent::isDataAwaiting()) { | ||
$meta = stream_get_meta_data($this->stream); | ||
return!$meta['timed_out'] && !$meta['eof']; | ||
} | ||
return false; | ||
} | ||
|
||
public function setBuffer($size, $direction = self::DIRECTION_ALL) | ||
{ | ||
$result = parent::setBuffer($size, $direction); | ||
if (self::DIRECTION_SEND === $direction | ||
&& function_exists('stream_set_chunk_size') && !$result | ||
) { | ||
return is_int(stream_set_chunk_size($this->stream, $size)); | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* Shutdown a full-duplex connection | ||
* | ||
* Shutdowns (partially or not) a full-duplex connection. | ||
* | ||
* @param string $direction The direction for which to disable further | ||
* communications. | ||
* | ||
* @return bool TRUE on success, FALSE on failure. | ||
*/ | ||
public function shutdown($direction = self::DIRECTION_ALL) | ||
{ | ||
$directionMap = array( | ||
self::DIRECTION_ALL => STREAM_SHUT_RDWR, | ||
self::DIRECTION_SEND => STREAM_SHUT_WR, | ||
self::DIRECTION_RECEIVE => STREAM_SHUT_RD | ||
); | ||
return array_key_exists($direction, $directionMap) | ||
&& stream_socket_shutdown($this->stream, $directionMap[$direction]); | ||
} | ||
} |
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
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
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
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
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
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
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