From a8e23cf57fd4a09ff9ff1076bdaab22d29cbe0d6 Mon Sep 17 00:00:00 2001 From: Yoshida Hiroshi Date: Thu, 7 Nov 2024 12:15:08 +0900 Subject: [PATCH] =?UTF-8?q?=E5=87=A6=E7=90=86=E5=8F=AF=E8=83=BD=E3=81=AA?= =?UTF-8?q?=E8=AA=AD=E3=81=BF=E8=BE=BC=E3=81=BF=E6=B8=88=E3=81=BF=E3=81=AE?= =?UTF-8?q?=E3=83=87=E3=83=BC=E3=82=BF=E3=81=8C=E3=81=BE=E3=81=A0=E3=81=82?= =?UTF-8?q?=E3=82=8B=E5=A0=B4=E5=90=88=E3=81=AF=E3=80=81=E3=81=9D=E3=81=AE?= =?UTF-8?q?=E3=83=87=E3=83=BC=E3=82=BF=E3=82=92=E5=87=A6=E7=90=86=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=8B=E3=82=89=E6=AC=A1=E3=81=AE=E8=AA=AD=E3=81=BF?= =?UTF-8?q?=E8=BE=BC=E3=81=BF=E3=81=AB=E9=80=B2=E3=82=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/handler.go b/handler.go index 7ac6070..d2dca31 100644 --- a/handler.go +++ b/handler.go @@ -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 {