Skip to content

Commit

Permalink
stream_socket_shutdown resources in ROS on close
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Jun 18, 2017
1 parent cc42b43 commit 161c734
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 4 additions & 0 deletions lib/ResourceOutputStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ private function send(string $data, bool $end = false): Promise {
* @return void
*/
public function close() {
if ($this->resource) {
\stream_socket_shutdown($this->resource, \STREAM_SHUT_WR);

This comment has been minimized.

Copy link
@kelunik

kelunik Jun 18, 2017

Author Member

This does work for TCP and Unix sockets, but not for pipes. If we could determine whether some resource is a pipe, we could use fclose on those.

}

$this->resource = null;
$this->writable = false;

Expand Down
12 changes: 2 additions & 10 deletions test/ResourceStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,9 @@ public function testLargePayloads() {
$b = new ResourceInputStream($right);

$length = 1 * 1024 * 1024; // 1M
$message = \str_repeat(".", $length);

$message = "";
for ($i = 0; $i < $length; $i++) {
$message .= \chr(\mt_rand(33, 125));
}

$a->end($message)->onResolve(function () use (&$a, &$left) {
// Let GC close resource
$a = null;
$left = null;
});
$a->end($message);

$received = "";
while (null !== $chunk = yield $b->read()) {
Expand Down

0 comments on commit 161c734

Please sign in to comment.