Page MenuHomePhabricator

D7769.diff

diff --git a/src/channel/PhutilChannel.php b/src/channel/PhutilChannel.php
--- a/src/channel/PhutilChannel.php
+++ b/src/channel/PhutilChannel.php
@@ -131,7 +131,13 @@
// busy wait).
if (!$r_sockets && !$w_sockets) {
- return;
+ return false;
+ }
+
+ if ($channel->isWriteBufferEmpty()) {
+ // If the channel's write buffer is empty, don't select the write
+ // sockets, since they're writable immediately.
+ $w_sockets = array();
}
foreach ($r_sockets as $socket) {
diff --git a/src/channel/PhutilExecChannel.php b/src/channel/PhutilExecChannel.php
--- a/src/channel/PhutilExecChannel.php
+++ b/src/channel/PhutilExecChannel.php
@@ -124,6 +124,9 @@
return $this->future->getWriteSockets();
}
+ protected function isWriteBufferEmpty() {
+ return $this->future->isWriteBufferEmpty();
+ }
/**
* If the wrapped @{class:ExecFuture} outputs data to stderr, we normally
diff --git a/src/channel/PhutilSocketChannel.php b/src/channel/PhutilSocketChannel.php
--- a/src/channel/PhutilSocketChannel.php
+++ b/src/channel/PhutilSocketChannel.php
@@ -148,9 +148,7 @@
}
protected function getWriteSockets() {
- if ($this->isWriteBufferEmpty()) {
- return array();
- } else if ($this->writeSocket) {
+ if ($this->writeSocket) {
return array($this->writeSocket);
} else {
return array();
diff --git a/src/future/exec/ExecFuture.php b/src/future/exec/ExecFuture.php
--- a/src/future/exec/ExecFuture.php
+++ b/src/future/exec/ExecFuture.php
@@ -487,6 +487,17 @@
/**
+ * Determine if the write buffer is empty.
+ *
+ * @return bool True if the write buffer is empty.
+ * @task internal
+ */
+ public function isWriteBufferEmpty() {
+ return !($this->stdin && $this->stdin->getByteLength());
+ }
+
+
+ /**
* Reads some bytes from a stream, discarding output once a certain amount
* has been accumulated.
*
diff --git a/src/utils/PhutilRope.php b/src/utils/PhutilRope.php
--- a/src/utils/PhutilRope.php
+++ b/src/utils/PhutilRope.php
@@ -11,6 +11,11 @@
private $length = 0;
private $buffers = array();
+
+ // This is is arbitrary, it's just the maximum size I'm reliably able to
+ // fwrite() to a pipe on OSX. In theory, we could tune this slightly based
+ // on the pipe buffer size, but any value similar to this shouldn't affect
+ // performance much.
private $segmentSize = 16384;
/**

File Metadata

Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/zz/zv/jtn3afego44pyot4
Default Alt Text
D7769.diff (2 KB)

Event Timeline