Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 55370c9

Browse files
committed
Fixed Connection::setStreamTimeout
1 parent 4817565 commit 55370c9

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,31 @@ 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->assertEquals(1, $timeTaken);
183+
184+
$meta = stream_get_meta_data($this->c->streamSocket());
185+
186+
$this->assertTrue($meta["timed_out"]);
187+
}
188+
164189
/**
165190
* Test Unsubscribe command.
166191
*

0 commit comments

Comments
 (0)