Skip to content

Commit 883311c

Browse files
authored
Merge pull request repejota#75 from byrnedo/hotfix/fix-set-stream-timeout
Fixed Connection::setStreamTimeout
2 parents 389b161 + 9738c53 commit 883311c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/Nats/Connection.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public function setStreamTimeout($seconds)
449449
if ($this->isConnected()) {
450450
if (is_int($seconds)) {
451451
try {
452-
return $this->streamWrapper->setStreamTimeout($this->streamSocket, $seconds);
452+
return stream_set_timeout($this->streamSocket, $seconds);
453453
} catch (\Exception $e) {
454454
return false;
455455
}
@@ -489,4 +489,13 @@ public function close()
489489
fclose($this->streamSocket);
490490
$this->streamSocket = null;
491491
}
492+
493+
494+
/**
495+
* @return resource
496+
*/
497+
public function streamSocket()
498+
{
499+
return $this->streamSocket;
500+
}
492501
}

test/ConnectionTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,32 @@ function ($message) use ($contentLen) {
161161

162162
}
163163

164+
/**
165+
* Test setting a timeout on the stream
166+
*
167+
* @return void
168+
*/
169+
public function testSetStreamTimeout()
170+
{
171+
$this->c->setStreamTimeout(1);
172+
$before = time();
173+
$this->c->request(
174+
"nonexistantsubject",
175+
"test",
176+
function ($message) {
177+
$this->fail("should never have gotten here");
178+
}
179+
);
180+
$timeTaken = time() - $before;
181+
182+
$this->assertGreaterThan(0, $timeTaken);
183+
$this->assertLessThan(3, $timeTaken);
184+
185+
$meta = stream_get_meta_data($this->c->streamSocket());
186+
187+
$this->assertTrue($meta["timed_out"]);
188+
}
189+
164190
/**
165191
* Test Unsubscribe command.
166192
*

0 commit comments

Comments
 (0)