Commit 1b075448 authored by tufengqi's avatar tufengqi

fix steam with swoole

parent 016c48f8
......@@ -45,7 +45,7 @@ class TPhpStream extends TTransport
private $write_ = false;
private static $fd;
private $fd;
public function __construct($mode)
{
......@@ -53,21 +53,21 @@ class TPhpStream extends TTransport
$this->write_ = $mode & self::MODE_W;
}
public static function getFd()
public function getFd()
{
return self::$fd;
return $this->fd;
}
public static function setFd($fd)
public function setFd($fd)
{
self::$fd = $fd;
$this->fd = $fd;
}
public function open()
{
if ($this->read_) {
if (defined('IS_SWOOLE_SERVICE') && true === IS_SWOOLE_SERVICE) {
$this->inStream_ = self::$fd;
$this->inStream_ = $this->fd;
} else {
$this->inStream_ = @fopen(self::inStreamName(), 'r');
}
......@@ -102,7 +102,12 @@ class TPhpStream extends TTransport
public function read($len)
{
if (defined('IS_SWOOLE_SERVICE') && IS_SWOOLE_SERVICE === true) {
fseek($fp, $len);
$data = co::fread($fp);
} else {
$data = @fread($this->inStream_, $len);
}
if ($data === false || $data === '') {
throw new TException('TPhpStream: Could not read ' . $len . ' bytes');
}
......@@ -113,7 +118,11 @@ class TPhpStream extends TTransport
public function write($buf)
{
while (TStringFuncFactory::create()->strlen($buf) > 0) {
if (defined('IS_SWOOLE_SERVICE') && IS_SWOOLE_SERVICE === true) {
$got = co::fwrite($this->outStream_, $buf);
} else {
$got = @fwrite($this->outStream_, $buf);
}
if ($got === 0 || $got === false) {
throw new TException(
'TPhpStream: Could not write ' . TStringFuncFactory::create()->strlen($buf) . ' bytes'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment