This is automatic generated document for things in Swow\Http\Protocol\ReceiverTrait class
Trait ReceiverTrait
http response / request receiver
This class is a generic class. Template T of (ServerRequestEntity | ResponseEntity)
Properties
protected $activeChunkedBody protected $autoUnmask protected $buffer protected $bufferLoadFactor protected $httpParser protected $parsedOffset protected $preserveBodyData protected $recvMessageTimeout protected $shouldKeepAlive protected $streamingChunkedResponse Methods
Method __constructReceiver
protected function __constructReceiver ( int $type , int $events ) : void Method finalizeChunkedBodyState
protected function finalizeChunkedBodyState ( ChunkedBodyState $state ) : void 提交流式 body 的最终状态到连接级上下文。
做三件事: 1) 标记 complete/finalized; 2) reset parser; 3) 按 parsedOffset 回收 buffer 并清空 activeChunkedBody。
Method getBufferLoadFactor
public function getBufferLoadFactor ( ) : float Method getRecvMessageTimeout
public function getRecvMessageTimeout ( ) : int Method guardPreviousChunkedBody
protected function guardPreviousChunkedBody ( ) : void 在解析下一条 HTTP 消息前,先处理上一条未完成的流式 chunked body。
触发时机:
- recvMessageEntity() 入口第一步。
副作用:
- 发现未完成 body 时直接关闭连接并将 shouldKeepAlive 置为 false。
Method handleChunkedBodyStreamClosed
protected function handleChunkedBodyStreamClosed ( ChunkedBodyState $state ) : void 处理业务层主动 close() 的流式 body。
设计意图:
- 业务可能只读取了前缀数据就关闭 body;
- 当前策略固定为“未完成即断开连接”,简化维护并避免状态分叉。
Method isAutoUnmask
public function isAutoUnmask ( ) : bool Returns bool Whether unmask WebSocket payload data automatically
Method isPreserveBodyData
public function isPreserveBodyData ( ) : bool Method isStreamingChunkedResponse
public function isStreamingChunkedResponse ( ) : bool Method pumpChunkedBodyStateToCompletion
protected function pumpChunkedBodyStateToCompletion ( ChunkedBodyState $state , ?int $timeout ) : void 一直推进直到 MESSAGE_COMPLETE(用于 getSize/toString/getContents 等全量语义)。
Method pumpChunkedBodyStateToLength
protected function pumpChunkedBodyStateToLength ( ChunkedBodyState $state , int $targetLength , ?int $timeout ) : void 核心推进器:按需把 bodyBuffer 推进到 targetLength,或推进到 finalized。
关键保证:
- parser 输入与 socket 字节流保持一致;
- 仅在 EVENT_MESSAGE_COMPLETE 时 finalize;
- 任何解析错误都视为连接不可复用。
Method recvMessageEntity
protected function recvMessageEntity ( ?int $timeout ) : T Todo The options must be managed in a unified way
Method recvWebSocketFrameEntity
public function recvWebSocketFrameEntity ( ) : WebSocketFrameEntity This method will unmask masked payloadData and clear the masking key automatically
Method setAutoUnmask
public function setAutoUnmask ( bool $enable ) : static Param bool $enable If true, WebSocket payload data will be unmasked automatically
Method setBufferLoadFactor
public function setBufferLoadFactor ( float $bufferLoadFactor ) : static Method setPreserveBodyData
public function setPreserveBodyData ( bool $enable ) : static Method setRecvMessageTimeout
public function setRecvMessageTimeout ( int $timeout ) : static Param int $timeout HTTP keep alive timeout in milliseconds
Method setStreamingChunkedResponse
public function setStreamingChunkedResponse ( bool $enable ) : static Method shouldKeepAlive
public function shouldKeepAlive ( ) : bool Method updateParsedOffsetAndRecycleBufferSpace
protected function updateParsedOffsetAndRecycleBufferSpace ( Buffer $buffer , int $parsedOffset ) : void