Skip to content

Commit a159449

Browse files
Merge pull request #13 from ElvenSpellmaker/fix/send-eof-on-invalid-read
Commands EOF when reading from an invalid buffer.
2 parents 7775583 + 261f89c commit a159449

File tree

5 files changed

+25
-16
lines changed

5 files changed

+25
-16
lines changed

src/PipeSys/Command/AbstractCommand.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,7 @@ public function runOnce()
5454
$firstRun = true;
5555
}
5656

57-
try
58-
{
59-
return $this->attemptRun($firstRun);
60-
}
61-
catch (InvalidBufferException $e)
62-
{
63-
$this->invalidate();
64-
return null;
65-
}
57+
return $this->attemptRun($firstRun);
6658
}
6759

6860
/**
@@ -82,6 +74,11 @@ private function attemptRun($firstRun)
8274
{
8375
$data = $this->attemptRead();
8476

77+
if ($data instanceof EOF)
78+
{
79+
$this->invalidate();
80+
}
81+
8582
if ($this->isReading())
8683
{
8784
return false;
@@ -155,7 +152,14 @@ private function handleResponse($data)
155152
{
156153
if ($data instanceof OutputIntent)
157154
{
158-
$this->write($data->getChannel(), $data->getContent());
155+
try
156+
{
157+
$this->write($data->getChannel(), $data->getContent());
158+
}
159+
catch (InvalidBufferException $e)
160+
{
161+
$this->invalidate();
162+
}
159163
}
160164
if ($data instanceof ReadIntent)
161165
{

src/PipeSys/Command/DelayedHead.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,5 @@ public function getCommand()
4646

4747
yield new OutputIntent($input);
4848
}
49-
50-
yield new OutputIntent(new EOF);
5149
}
5250
}

src/PipeSys/Command/Sprunge.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Sprunge extends AbstractCommand
2222
*/
2323
public function getCommand()
2424
{
25+
2526
while (true)
2627
{
2728
$input = (yield new ReadIntent);
@@ -34,9 +35,8 @@ public function getCommand()
3435
$this->text .= $input;
3536
}
3637

37-
$curl = curl_init();
38+
$curl = curl_init('http://sprunge.us');
3839

39-
curl_setopt($curl, CURLOPT_URL, 'http://sprunge.us');
4040
curl_setopt($curl, CURLOPT_POST, 1);
4141
curl_setopt($curl, CURLOPT_POSTFIELDS, ['sprunge' => $this->text]);
4242

src/PipeSys/IO/IOableTrait.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@ public function read($key)
123123
throw new IOException("The IOableObject in position '$key' does not implement the InputInterface!");
124124
}
125125

126-
return $this->ios[$key]['channel']->read();
126+
try
127+
{
128+
return $this->ios[$key]['channel']->read();
129+
}
130+
catch (InvalidBufferException $e)
131+
{
132+
return new EOF;
133+
}
127134
}
128135

129136
/**

src/PipeSys/Scheduler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function run()
5757
{
5858
$result = $command->runOnce();
5959

60-
if ($result === null)
60+
if ($result === null || ! $command->isValid())
6161
{
6262
unset($this->commands[$key]);
6363
}

0 commit comments

Comments
 (0)