tourze/quic-streams
最新稳定版本:0.0.1
Composer 安装命令:
composer require tourze/quic-streams
包简介
QUIC Protocol Streams Management Implementation
README 文档
README
QUIC协议流管理实现包,提供完整的QUIC流生命周期管理功能。
Features
- ✅ Bidirectional and unidirectional stream support
- ✅ Stream state machine management
- ✅ Data buffering and ordering
- ✅ Flow control integration
- ✅ Exception error handling
- ✅ Memory-optimized buffer management
Installation
composer require tourze/quic-streams
Requirements
- PHP 8.1 or higher
- tourze/quic-core
- tourze/quic-flow-control
- tourze/quic-frames
Quick Start
创建流管理器
use Tourze\QUIC\Streams\StreamManager; use Tourze\QUIC\FlowControl\FlowControlManager; // 创建流控制管理器(可选) $flowControlManager = new FlowControlManager(); // 创建流管理器 $streamManager = new StreamManager( isServer: true, flowControlManager: $flowControlManager );
创建流
use Tourze\QUIC\Core\Enum\StreamType; // 创建双向流 $bidirectionalStream = $streamManager->createStream(StreamType::CLIENT_BIDI); // 创建单向流 $unidirectionalStream = $streamManager->createStream(StreamType::CLIENT_UNI);
发送和接收数据
// 发送数据 $stream->send('Hello QUIC!', fin: false); $stream->send('Final message', fin: true); // 接收数据 $stream->receive('Received data', offset: 0, fin: false);
流状态管理
use Tourze\QUIC\Streams\StreamStateMachine; $stateMachine = new StreamStateMachine(); // 状态转换 $success = $stateMachine->transitionSend(StreamSendState::SEND); // 检查状态 if ($stateMachine->canSend()) { // 可以发送数据 } if ($stateMachine->isClosed()) { // 流已关闭 }
缓冲区管理
use Tourze\QUIC\Streams\StreamBuffer; // 创建缓冲区(默认1MB) $buffer = new StreamBuffer(); // 添加发送数据 $offset = $buffer->addSendData('Data to send'); // 获取发送数据 $sendData = $buffer->getSendData(maxLength: 1200); // 添加接收数据 $buffer->addRecvData('Received data', offset: 0); // 获取连续的接收数据 $recvData = $buffer->getRecvData();
API Reference
核心类
Stream- 抽象流基类BidirectionalStream- 双向流实现UnidirectionalStream- 单向流实现StreamManager- 流管理器StreamBuffer- 数据缓冲区StreamStateMachine- 流状态机StreamException- 流异常
流类型
根据RFC 9000规范:
StreamType::CLIENT_BIDI(0) - 客户端发起的双向流StreamType::SERVER_BIDI(1) - 服务器发起的双向流StreamType::CLIENT_UNI(2) - 客户端发起的单向流StreamType::SERVER_UNI(3) - 服务器发起的单向流
Error Handling
use Tourze\QUIC\Streams\StreamException; use Tourze\QUIC\Core\Enum\QuicError; try { $stream->send('data'); } catch (StreamException $e) { $quicError = $e->getQuicError(); echo "QUIC Error: " . $quicError->name; }
Testing
# 运行单元测试 ./vendor/bin/phpunit packages/quic-streams/tests # 运行静态分析 ./vendor/bin/phpstan analyse packages/quic-streams/src --level=max
Dependencies
tourze/quic-core- QUIC核心定义tourze/quic-frames- QUIC帧处理tourze/quic-flow-control- 流量控制
Contributing
Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-03