Custom instances of HStream impossible to write
- 主要语言
- Haskell
- 星标
- 186
- 派生
- 59
- PR 合并指标
- 30 天内没有已合并 PR
描述
It would be nice to be able to have an instance of [`HStream`](http://hackage.haskell.org/package/HTTP-4000.2.19/docs/Network-TCP.html#t:HStream) that allows to stream without using lazy I/O; in particular, an instance that would allow us to close the connection when we no longer want the rest of the response body.
However, in order to define a custom type with a corresponding `HStream` instance one needs to provide, amongst other things, implementations of
``` haskell
openStream :: String -> Int -> IO (HandleStream bufType)
close :: HandleStream bufType -> IO ()
```
For the implementation of `openStream` we can use
``` haskell
openTCPConnection :: BufferType ty => String -> Int -> IO (HandleStream ty)
```
However, for the implementation of `close` we are stuck; there is no function analogous to `openTCPConnection` that allows us to close a `HandleStream`.
Although we have
``` haskell
hstreamToConnection :: HandleStream String -> Connection
```
and there is a [`Stream`](http://hackage.haskell.org/package/HTTP-4000.2.19/docs/Network-Stream.html#t:Stream) instance for [`Connection`](http://hackage.haskell.org/package/HTTP-4000.2.19/docs/Network-TCP.html#t:Connection), `hstreamToConnection` works _only_ for `HandleStream String`, so that doesn't help either.
Finally, the [`HandleStream`](http://hackage.haskell.org/package/HTTP-4000.2.19/docs/Network-TCP.html#t:HandleStream) type is completely opaque (it does not even satisfy `Functor`) so we cannot define a `HStream` instance for one `bufType` in terms of the `HStream` instance for another. If we had _some_ way of defining new instances in terms of old instances (for instance, reuse the instance for lazy bytestrings, but somehow retain a handle to the corresponding `HandleStream` so that we can close it explicitly) that would be great.
贡献指南
这个仓库没有索引到贡献指南
调研方向
先从 Network.TCP 中的 HStream、HandleStream、openStream、close 和 openTCPConnection 开始,然后检查 Network.Stream 中的 hstreamToConnection 和 Connection。确定一种 API,使自定义 HStream 实例能够在不使用 lazy I/O、也不依赖特定于 String 的转换的情况下关闭其 HandleStream。完成标准是自定义缓冲区类型可以定义显式的连接清理。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- haskell
- 领域
- networking
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100