Transporter::syncSendAndReceive PHP Method

syncSendAndReceive() public method

public syncSendAndReceive ( $buffer, stdClass $context )
$context stdClass
    public function syncSendAndReceive($buffer, stdClass $context)
    {
        $client = $this->client;
        $timeout = $context->timeout / 1000;
        $sec = floor($timeout);
        $usec = ($timeout - $sec) * 1000;
        $trycount = 0;
        $errno = 0;
        $errstr = '';
        while ($trycount <= 1) {
            if ($this->stream === null) {
                $this->stream = @stream_socket_client($this->client->uri, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($client->options));
                if ($this->stream === false) {
                    $this->stream = null;
                    throw new Exception($errstr, $errno);
                }
            }
            $stream = $this->stream;
            @stream_set_read_buffer($stream, $client->readBuffer);
            @stream_set_write_buffer($stream, $client->writeBuffer);
            if (@stream_set_timeout($stream, $sec, $usec) == false) {
                if ($trycount > 0) {
                    throw $this->getLastError("unknown error");
                }
                $trycount++;
            } else {
                break;
            }
        }
        if ($this->write($stream, $buffer) === false) {
            throw $this->getLastError("request write error");
        }
        $response = $this->read($stream, $buffer);
        if ($response === false) {
            throw $this->getLastError("response read error");
        }
        return $response;
    }