Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Jan 19, 2020
2 parents 541639e + b57165d commit f41d945
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/YurunHttp/Http2/IHttp2Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,19 @@ public function isSSL();
*/
public function getRecvingCount();

/**
* 设置超时时间,单位:秒
*
* @param float|null $timeout
* @return void
*/
public function setTimeout($timeout);

/**
* 获取超时时间,单位:秒
*
* @return float|null
*/
public function getTimeout();

}
40 changes: 40 additions & 0 deletions src/YurunHttp/Http2/SwooleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ class SwooleClient implements IHttp2Client
*/
private $requestMap = [];

/**
* 超时时间,单位:秒
*
* @var float
*/
private $timeout;

/**
* @param string $host
* @param int $port
Expand Down Expand Up @@ -96,6 +103,12 @@ public function connect()
if($client)
{
$this->http2Client = $client;
if($this->timeout)
{
$this->http2Client->set([
'timeout' => $this->timeout,
]);
}
$this->startRecvCo();
return true;
}
Expand Down Expand Up @@ -330,4 +343,31 @@ public function setServerPushQueueLength($serverPushQueueLength)
return $this;
}

/**
* 设置超时时间,单位:秒
*
* @param float|null $timeout
* @return void
*/
public function setTimeout($timeout)
{
$this->timeout = $timeout;
if($this->http2Client)
{
$this->http2Client->set([
'timeout' => $timeout,
]);
}
}

/**
* 获取超时时间,单位:秒
*
* @return float|null
*/
public function getTimeout()
{
return $this->timeout;
}

}
3 changes: 3 additions & 0 deletions tests/unit/Http2/SwooleHttp2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function testMuiltCo()
$this->call(function(){
$uri = new Uri($this->http2Host);
$client = new SwooleClient($uri->getHost(), Uri::getServerPort($uri), 'https' === $uri->getScheme());
$client->setTimeout(3);
go(function() use($client){
$result = $client->recv();
$this->assertFalse($result->success);
Expand Down Expand Up @@ -133,6 +134,8 @@ public function testPipeline1()

$this->assertTrue($client->connect());

$client->setTimeout(3);

$http = new HttpRequest;
$http->protocolVersion = '2.0';
$http->timeout = 3000;
Expand Down

0 comments on commit f41d945

Please sign in to comment.