Commit b2edd9c7 authored by tufengqi's avatar tufengqi

swoole add fread

parent 5886c610
...@@ -66,7 +66,7 @@ class TPhpStream extends TTransport ...@@ -66,7 +66,7 @@ class TPhpStream extends TTransport
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') && IS_SWOOLE_SERVICE === true) {
$this->inStream_ = $this->fd; $this->inStream_ = $this->fd;
} else { } else {
$this->inStream_ = @fopen(self::inStreamName(), 'r'); $this->inStream_ = @fopen(self::inStreamName(), 'r');
...@@ -103,26 +103,23 @@ class TPhpStream extends TTransport ...@@ -103,26 +103,23 @@ class TPhpStream extends TTransport
public function read($len) public function read($len)
{ {
if (defined('IS_SWOOLE_SERVICE') && IS_SWOOLE_SERVICE === true) { if (defined('IS_SWOOLE_SERVICE') && IS_SWOOLE_SERVICE === true) {
fseek($fp, $len); $cur = ftell($this->inStream_);
$data = co::fread($fp); $data = co::fread($this->inStream_, $len);
fseek($this->inStream_, $len, SEEK_CUR);
$data = TStringFuncFactory::create()->substr($data, 0, $len);
} else { } else {
$data = @fread($this->inStream_, $len); $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');
} }
return $data; return $data;
} }
public function write($buf) public function write($buf)
{ {
while (TStringFuncFactory::create()->strlen($buf) > 0) { while (TStringFuncFactory::create()->strlen($buf) > 0) {
if (defined('IS_SWOOLE_SERVICE') && IS_SWOOLE_SERVICE === true) { $got = @fwrite($this->outStream_, $buf);
$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