Skip to content

Commit

Permalink
処理可能な読み込み済みのデータがまだある場合は、そのデータを処理してから次の読み込みに進む
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexa committed Nov 7, 2024
1 parent 7bda005 commit a8e23cf
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,43 @@ func readPacketWithHeader(reader io.Reader) (io.Reader, error) {
// 次の payload 処理へ
payload = p[payloadLength:]
length = len(payload)

// 次の payload がすでにある場合の処理
for {
if length > 20 {
h = payload[0:20]
p = payload[20:length]

payloadLength = int(binary.BigEndian.Uint32(h[16:20]))

// すでに次の payload が全てある場合
if length == (20 + payloadLength) {
if _, err := w.Write(p); err != nil {
// TODO: ログ出力
return
}
payload = []byte{}
length = 0
continue
}

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

// 次の payload 処理へ
payload = p[payloadLength:]
length = len(payload)
continue
}
} else {
// payload が足りないので、次の読み込みへ
break
}
}

continue
}
} else {
Expand Down

0 comments on commit a8e23cf

Please sign in to comment.