Merge pull request #1164 from murgatroid99/php_metadata_expectations

Do not expect metadata until expecting first read
pull/1172/head
donnadionne 10 years ago
commit fe77f081cf
  1. 1
      src/php/lib/Grpc/AbstractCall.php
  2. 14
      src/php/lib/Grpc/BidiStreamingCall.php
  3. 7
      src/php/lib/Grpc/ClientStreamingCall.php

@ -47,6 +47,7 @@ abstract class AbstractCall {
public function __construct(Channel $channel, $method, $deserialize) {
$this->call = new Call($channel, $method, Timeval::inf_future());
$this->deserialize = $deserialize;
$this->metadata = null;
}
/**

@ -43,10 +43,7 @@ class BidiStreamingCall extends AbstractCall {
* @param array $metadata Metadata to send with the call, if applicable
*/
public function start($metadata) {
$event = $this->call->start_batch([
OP_SEND_INITIAL_METADATA => $metadata,
OP_RECV_INITIAL_METADATA => true]);
$this->metadata = $event->metadata;
$this->call->start_batch([OP_SEND_INITIAL_METADATA => $metadata]);
}
/**
@ -54,7 +51,14 @@ class BidiStreamingCall extends AbstractCall {
* @return The next value from the server, or null if there is none
*/
public function read() {
$read_event = $this->call->start_batch([OP_RECV_MESSAGE => true]);
$batch = [OP_RECV_MESSAGE => true];
if ($this->metadata === null) {
$batch[OP_RECV_INITIAL_METADATA] = true;
}
$read_event = $this->call->start_batch($batch);
if ($this->metadata === null) {
$this->metadata = $read_event->metadata;
}
return $this->deserializeResponse($read_event->message);
}

@ -44,10 +44,7 @@ class ClientStreamingCall extends AbstractCall {
* @param array $metadata Metadata to send with the call, if applicable
*/
public function start($arg_iter, $metadata = array()) {
$event = $this->call->start_batch([
OP_SEND_INITIAL_METADATA => $metadata,
OP_RECV_INITIAL_METADATA => true]);
$this->metadata = $event->metadata;
$event = $this->call->start_batch([OP_SEND_INITIAL_METADATA => $metadata]);
foreach($arg_iter as $arg) {
$this->call->start_batch([OP_SEND_MESSAGE => $arg->serialize()]);
}
@ -60,8 +57,10 @@ class ClientStreamingCall extends AbstractCall {
*/
public function wait() {
$event = $this->call->start_batch([
OP_RECV_INITIAL_METADATA => true,
OP_RECV_MESSAGE => true,
OP_RECV_STATUS_ON_CLIENT => true]);
$this->metadata = $event->metadata;
return array($this->deserializeResponse($event->message), $event->status);
}
}
Loading…
Cancel
Save