Skip to content

Commit

Permalink
Fix sniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Aug 24, 2023
1 parent edad4d1 commit 6371a13
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions common/sniff/sniff.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@ func PeekStream(ctx context.Context, conn net.Conn, buffer *buf.Buffer, timeout
if timeout == 0 {
timeout = C.ReadPayloadTimeout
}
err := conn.SetReadDeadline(time.Now().Add(timeout))
if err != nil {
return nil, E.Cause(err, "set read deadline")
}
_, err = buffer.ReadOnceFrom(conn)
err = E.Errors(err, conn.SetReadDeadline(time.Time{}))
if err != nil {
return nil, E.Cause(err, "read payload")
deadline := time.Now().Add(timeout)
for i := 0; ; i++ {
err := conn.SetReadDeadline(deadline)
if err != nil {
return nil, E.Cause(err, "set read deadline")
}
_, err = buffer.ReadOnceFrom(conn)
err = E.Errors(err, conn.SetReadDeadline(time.Time{}))
if err != nil {
if i > 0 {
break
}
return nil, E.Cause(err, "read payload")
}
}
var metadata *adapter.InboundContext
var errors []error
for _, sniffer := range sniffers {
metadata, err = sniffer(ctx, bytes.NewReader(buffer.Bytes()))
metadata, err := sniffer(ctx, bytes.NewReader(buffer.Bytes()))
if metadata != nil {
return metadata, nil
}
Expand Down

0 comments on commit 6371a13

Please sign in to comment.