Skip to content

Commit

Permalink
modify result
Browse files Browse the repository at this point in the history
  • Loading branch information
stelin committed Apr 10, 2018
1 parent 409120a commit 2c477a6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public function call(string $func, array $params)
}

App::profileStart($profileKey);
$result = $client->recv();
$result = $client->receive();
App::profileEnd($profileKey);
$connectPool->release($client);
$client->release(true);

App::debug(sprintf('%s call %s success, data=%', $this->interface, $func, json_encode($data, JSON_UNESCAPED_UNICODE)));
$result = $packer->unpack($result);
Expand Down Expand Up @@ -170,7 +170,6 @@ private function deferCall(string $func, array $params)

$result = $circuitBreaker->call([$connection, 'send'], [$packData], $fallback);

// 错误处理
if ($result === null || $result === false) {
return null;
}
Expand All @@ -196,13 +195,13 @@ private function deferCall(string $func, array $params)
private function getResult(ConnectionInterface $connection = null, string $profileKey = '', $result = null)
{
if (App::isCoContext()) {
$serviceCoResult = new ServiceCoResult($connection, $profileKey);
$serviceCoResult = new ServiceCoResult($result, $connection, $profileKey);
$serviceCoResult->setFallbackData($result);

return $serviceCoResult;
}

return new ServiceDataResult($result, $connection);
return new ServiceDataResult($result, $connection, $profileKey);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Service/ServiceCoResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace Swoft\Rpc\Client\Service;

use Swoft\App;
use Swoft\Core\AbstractCoResult;
use Swoft\Core\AbstractResult;

/**
* The cor result of server
* ServiceCoResult
*/
class ServiceCoResult extends AbstractCoResult
class ServiceCoResult extends AbstractResult
{
/**
* @var mixed
Expand Down
2 changes: 1 addition & 1 deletion src/Service/ServiceConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function createConnection()

public function receive()
{
$result = $this->connection->recv();
$result = $this->recv();
$this->recv = true;
return $result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Service/ServiceDataResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace Swoft\Rpc\Client\Service;

use Swoft\App;
use Swoft\Core\AbstractDataResult;
use Swoft\Core\AbstractResult;

/**
* The data result of service
*/
class ServiceDataResult extends AbstractDataResult
class ServiceDataResult extends AbstractResult
{
/**
* @var mixed
Expand Down
14 changes: 13 additions & 1 deletion src/Service/SyncServiceConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,26 @@ public function check(): bool
return true;
}

/**
* @return string
*/
public function receive()
{
$result = $this->recv();
$this->recv = true;
return $result;
}

/**
* @param string $data
*
* @return bool
*/
public function send(string $data): bool
{
return fwrite($this->connection, $data);
$result = fwrite($this->connection, $data);
$this->recv = false;
return $result;
}

/**
Expand Down

0 comments on commit 2c477a6

Please sign in to comment.