public function sendResponse()

in provider/fsof/FSOFProtocol.php [398:479]


    public function sendResponse(DubboResponse $response, $client_id)
    {
        try
		{
            $send_data = $this->parser->packResponse($response);
            $send_len = strlen($send_data);
    
            //默认所有server的response最大5M,每个分包允许重发2次,预计最多10次循环,防止网络出错导致server直接挂死在循环中
            $cnt = (($send_len / DubboParser::RESPONSE_TCP_SEGMENT_LEN) + 1) * 2;
            $tmp_len = $send_len;
            for ($i = 0; $i < $cnt; $i++)
			{
                if ($tmp_len > DubboParser::RESPONSE_TCP_SEGMENT_LEN)
				{
                    //大于1M 分段发送
                    $tmp_data = substr($send_data, 0, DubboParser::RESPONSE_TCP_SEGMENT_LEN);
                    if ($this->swoole_server->send($client_id, $tmp_data))
					{
                        $tmp_len -= DubboParser::RESPONSE_TCP_SEGMENT_LEN;
                        $send_data = substr($send_data, DubboParser::RESPONSE_TCP_SEGMENT_LEN);
                    }
					else
					{
                        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
                        {
                            $last_error_no = $this->swoole_server->errno();
                        }
                        else
                        {
                            $last_error_no = swoole_errno();
                        }
                        if (0 == $last_error_no)
						{
                            //表示该连接己关闭
                            $this->logger->error("当前连接己关闭,发送失败");
                            break;
                        }
						else
						{
                            $this->logger->error('send response split package fail one time!');
                        }
                    }
                    $this->logger->warn('the length of response: '.$send_len.'; send split package '.$i.'/'.$cnt);
                }
				else
				{
                    //小于1M一次性发完
                    if ($this->swoole_server->send($client_id, $send_data))
					{
                        break;
                    }
					else
					{
                        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
                        {
                            $last_error_no = $this->swoole_server->errno();
                        }
                        else
                        {
                            $last_error_no = swoole_errno();
                        }
                        if (0 == $last_error_no)
						{
                            //表示该连接己关闭
                            $this->logger->error("当前连接己关闭,发送失败");
                            break;
                        }
						else
						{
                            $this->logger->error('send response last package fail one time!');
                        }
                    }
                }
            }
        }
		catch (\Exception $e)
		{
            $this->logger->error($e->getMessage(), $e);
        }

        return $send_len;
    }