Commit 1b075448 authored by tufengqi's avatar tufengqi

fix steam with swoole

parent 016c48f8
...@@ -45,7 +45,7 @@ class TPhpStream extends TTransport ...@@ -45,7 +45,7 @@ class TPhpStream extends TTransport
private $write_ = false; private $write_ = false;
private static $fd; private $fd;
public function __construct($mode) public function __construct($mode)
{ {
...@@ -53,21 +53,21 @@ class TPhpStream extends TTransport ...@@ -53,21 +53,21 @@ class TPhpStream extends TTransport
$this->write_ = $mode & self::MODE_W; $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() public function open()
{ {
if ($this->read_) { if ($this->read_) {
if (defined('IS_SWOOLE_SERVICE') && true === IS_SWOOLE_SERVICE) { if (defined('IS_SWOOLE_SERVICE') && true === IS_SWOOLE_SERVICE) {
$this->inStream_ = self::$fd; $this->inStream_ = $this->fd;
} else { } else {
$this->inStream_ = @fopen(self::inStreamName(), 'r'); $this->inStream_ = @fopen(self::inStreamName(), 'r');
} }
...@@ -102,7 +102,12 @@ class TPhpStream extends TTransport ...@@ -102,7 +102,12 @@ class TPhpStream extends TTransport
public function read($len) public function read($len)
{ {
$data = @fread($this->inStream_, $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 === '') { if ($data === false || $data === '') {
throw new TException('TPhpStream: Could not read ' . $len . ' bytes'); throw new TException('TPhpStream: Could not read ' . $len . ' bytes');
} }
...@@ -113,7 +118,11 @@ class TPhpStream extends TTransport ...@@ -113,7 +118,11 @@ class TPhpStream extends TTransport
public function write($buf) public function write($buf)
{ {
while (TStringFuncFactory::create()->strlen($buf) > 0) { while (TStringFuncFactory::create()->strlen($buf) > 0) {
$got = @fwrite($this->outStream_, $buf); 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) { if ($got === 0 || $got === false) {
throw new TException( throw new TException(
'TPhpStream: Could not write ' . TStringFuncFactory::create()->strlen($buf) . ' bytes' '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