Differential D18859 Diff 45240 src/applications/diffusion/ssh/DiffusionMercurialWireClientSSHProtocolChannel.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/ssh/DiffusionMercurialWireClientSSHProtocolChannel.php
Show First 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | while (true) { | ||||
$this->argumentName = $arg; | $this->argumentName = $arg; | ||||
$this->state = 'argv-value'; | $this->state = 'argv-value'; | ||||
$this->expectArgumentCount--; | $this->expectArgumentCount--; | ||||
} else { | } else { | ||||
$this->state = 'arguments'; | $this->state = 'arguments'; | ||||
} | } | ||||
} else if ($this->state == 'data-length') { | } else if ($this->state == 'data-length') { | ||||
// We're reading the length of a chunk of raw data. It looks like | |||||
// this: | |||||
// | |||||
// <length-in-bytes>\n | |||||
// | |||||
// The length is human-readable text (for example, "4096"), and | |||||
// may be 0. | |||||
$line = $this->readProtocolLine(); | $line = $this->readProtocolLine(); | ||||
if ($line === null) { | if ($line === null) { | ||||
break; | break; | ||||
} | } | ||||
$this->expectBytes = (int)$line; | $this->expectBytes = (int)$line; | ||||
if (!$this->expectBytes) { | if (!$this->expectBytes) { | ||||
$messages[] = $this->newDataMessage(''); | $messages[] = $this->newDataMessage(''); | ||||
$this->initializeState(); | $this->initializeState(); | ||||
} else { | } else { | ||||
$this->state = 'data-bytes'; | $this->state = 'data-bytes'; | ||||
} | } | ||||
} else if ($this->state == 'data-bytes') { | } else if ($this->state == 'data-bytes') { | ||||
// We're reading some known, nonzero number of raw bytes of data. | |||||
// If we don't have any more bytes on the buffer yet, just bail: | // If we don't have any more bytes on the buffer yet, just bail: | ||||
// otherwise, we'll emit a pointless and possibly harmful 0-byte data | // otherwise, we'll emit a pointless and possibly harmful 0-byte data | ||||
// frame. See T13036 for discussion. | // frame. See T13036 for discussion. | ||||
if (!strlen($this->buffer)) { | if (!strlen($this->buffer)) { | ||||
break; | break; | ||||
} | } | ||||
$bytes = substr($this->buffer, 0, $this->expectBytes); | $bytes = substr($this->buffer, 0, $this->expectBytes); | ||||
$this->buffer = substr($this->buffer, strlen($bytes)); | $this->buffer = substr($this->buffer, strlen($bytes)); | ||||
$this->expectBytes -= strlen($bytes); | $this->expectBytes -= strlen($bytes); | ||||
// NOTE: We emit a data frame as soon as we read some data. This can | |||||
// cause us to repackage frames: for example, if we receive one large | |||||
// frame slowly, we may emit it as several smaller frames. In theory | |||||
// this is good; in practice, Mercurial never seems to select a frame | |||||
// size larger than 4096 bytes naturally and this may be more | |||||
// complexity and trouble than it is worth. See T13036. | |||||
$messages[] = $this->newDataMessage($bytes); | $messages[] = $this->newDataMessage($bytes); | ||||
if (!$this->expectBytes) { | if (!$this->expectBytes) { | ||||
// We've finished reading this chunk, so go read the next chunk. | // We've finished reading this chunk, so go read the next chunk. | ||||
$this->state = 'data-length'; | $this->state = 'data-length'; | ||||
} else { | } else { | ||||
// We're waiting for more data, and have read everything available | // We're waiting for more data, and have read everything available | ||||
// to us so far. | // to us so far. | ||||
Show All 11 Lines |