Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14442937
D7773.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D7773.diff
View Options
Index: src/channel/PhutilChannel.php
===================================================================
--- src/channel/PhutilChannel.php
+++ src/channel/PhutilChannel.php
@@ -32,9 +32,13 @@
abstract class PhutilChannel {
private $ibuf = '';
- private $obuf = '';
+ private $obuf;
private $name;
+ public function __construct() {
+ $this->obuf = new PhutilRope();
+ }
+
/* -( Reading and Writing )------------------------------------------------ */
@@ -72,7 +76,7 @@
throw new Exception("PhutilChannel->write() may only write strings!");
}
- $this->obuf .= $bytes;
+ $this->obuf->append($bytes);
return $this;
}
@@ -183,13 +187,13 @@
$this->ibuf .= $in;
}
- while (strlen($this->obuf)) {
- $len = $this->writeBytes($this->obuf);
+ while ($this->obuf->getByteLength()) {
+ $len = $this->writeBytes($this->obuf->getAnyPrefix());
if (!$len) {
// Writing is blocked for now.
break;
}
- $this->obuf = substr($this->obuf, $len);
+ $this->obuf->removeBytesFromHead($len);
}
return $this->isOpen();
@@ -320,7 +324,7 @@
*
* @task impl
*/
- protected function isReadBufferEmpty() {
+ public function isReadBufferEmpty() {
return (strlen($this->ibuf) == 0);
}
@@ -332,8 +336,20 @@
*
* @task impl
*/
- protected function isWriteBufferEmpty() {
- return (strlen($this->obuf) == 0);
+ public function isWriteBufferEmpty() {
+ return !$this->getWriteBufferSize();
+ }
+
+
+ /**
+ * Get the number of bytes we're currently waiting to write.
+ *
+ * @return int Number of waiting bytes.
+ *
+ * @task impl
+ */
+ public function getWriteBufferSize() {
+ return $this->obuf->getByteLength();
}
Index: src/channel/PhutilChannelChannel.php
===================================================================
--- src/channel/PhutilChannelChannel.php
+++ src/channel/PhutilChannelChannel.php
@@ -15,6 +15,7 @@
private $channel;
public function __construct(PhutilChannel $channel) {
+ parent::__construct();
$this->channel = $channel;
$this->didConstruct();
}
@@ -68,14 +69,18 @@
return $this->channel->getWriteSockets();
}
- protected function isReadBufferEmpty() {
+ public function isReadBufferEmpty() {
return $this->channel->isReadBufferEmpty();
}
- protected function isWriteBufferEmpty() {
+ public function isWriteBufferEmpty() {
return $this->channel->isWriteBufferEmpty();
}
+ public function getWriteBufferSize() {
+ return $this->channel->getWriteBufferSize();
+ }
+
public function flush() {
$this->channel->flush();
return $this;
Index: src/channel/PhutilExecChannel.php
===================================================================
--- src/channel/PhutilExecChannel.php
+++ src/channel/PhutilExecChannel.php
@@ -63,6 +63,8 @@
* @task construct
*/
public function __construct(ExecFuture $future) {
+ parent::__construct();
+
// Make an empty write to keep the stdin pipe open. By default, futures
// close this pipe when they start.
$future->write('', $keep_pipe = true);
@@ -124,10 +126,14 @@
return $this->future->getWriteSockets();
}
- protected function isWriteBufferEmpty() {
+ public function isWriteBufferEmpty() {
return $this->future->isWriteBufferEmpty();
}
+ public function getWriteBufferSize() {
+ return $this->future->getWriteBufferSize();
+ }
+
/**
* If the wrapped @{class:ExecFuture} outputs data to stderr, we normally
* throw an exception. Instead, you can provide a callback handler that will
Index: src/channel/PhutilSocketChannel.php
===================================================================
--- src/channel/PhutilSocketChannel.php
+++ src/channel/PhutilSocketChannel.php
@@ -42,6 +42,7 @@
* @task construct
*/
public function __construct($read_socket, $write_socket = null) {
+ parent::__construct();
foreach (array($read_socket, $write_socket) as $socket) {
if (!$socket) {
Index: src/future/exec/ExecFuture.php
===================================================================
--- src/future/exec/ExecFuture.php
+++ src/future/exec/ExecFuture.php
@@ -513,7 +513,21 @@
* @task internal
*/
public function isWriteBufferEmpty() {
- return !($this->stdin && $this->stdin->getByteLength());
+ return !$this->getWriteBufferSize();
+ }
+
+
+ /**
+ * Determine the number of bytes in the write buffer.
+ *
+ * @return int Number of bytes in the write buffer.
+ * @task internal
+ */
+ public function getWriteBufferSize() {
+ if (!$this->stdin) {
+ return 0;
+ }
+ return $this->stdin->getByteLength();
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 27, 9:14 AM (11 h, 27 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6931472
Default Alt Text
D7773.diff (4 KB)
Attached To
Mode
D7773: Use PhutilRope for Channel write buffers and make write buffer details public
Attached
Detach File
Event Timeline
Log In to Comment