haskell / haskell/HTTP

Custom instances of HStream impossible to write

オープン
#86 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
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 を調べます。カスタム HStream インスタンスが lazy I/O を使わず、また String 固有の変換に依存せずに自身の HandleStream を閉じられる API を決定します。カスタムバッファ型が明示的な接続クリーンアップを定義できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
haskell
領域
networking
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。