Skip to content

Commit

Permalink
エラー時の close 処理を入れる
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexa committed Nov 7, 2024
1 parent 74ae761 commit be7f386
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ func readPacketWithHeader(reader io.Reader) (io.Reader, error) {
r, w := io.Pipe()

go func() {
defer w.Close()

length := 0
payloadLength := 0
var payload []byte
Expand All @@ -245,7 +243,7 @@ func readPacketWithHeader(reader io.Reader) (io.Reader, error) {
buf := make([]byte, 20+0xffff)
n, err := reader.Read(buf)
if err != nil {
// TODO: ログ出力
w.CloseWithError(err)
return
}

Expand All @@ -261,7 +259,7 @@ func readPacketWithHeader(reader io.Reader) (io.Reader, error) {

if length == (20 + payloadLength) {
if _, err := w.Write(p); err != nil {
// TODO: ログ出力
w.CloseWithError(err)
return
}
payload = []byte{}
Expand All @@ -279,7 +277,7 @@ func readPacketWithHeader(reader io.Reader) (io.Reader, error) {
// 次の frame が含まれている場合
if length > (20 + payloadLength) {
if _, err := w.Write(p[:payloadLength]); err != nil {
// TODO: ログ出力
w.CloseWithError(err)
return
}
// 次の payload 処理へ
Expand All @@ -297,7 +295,7 @@ func readPacketWithHeader(reader io.Reader) (io.Reader, error) {
// すでに次の payload が全てある場合
if length == (20 + payloadLength) {
if _, err := w.Write(p); err != nil {
// TODO: ログ出力
w.CloseWithError(err)
return
}
payload = []byte{}
Expand All @@ -307,7 +305,7 @@ func readPacketWithHeader(reader io.Reader) (io.Reader, error) {

if length > (20 + payloadLength) {
if _, err := w.Write(p[:payloadLength]); err != nil {
// TODO: ログ出力
w.CloseWithError(err)
return
}

Expand Down

0 comments on commit be7f386

Please sign in to comment.