Skip to Content [alt-c]

Comment

In reply to Comment by Reader Nuno

Anonymous on 2022-10-17 at 10:34:

If you're using this on Linux, I advise doing away with the io.MultiReader. Just return the bytes.Buffer, and io.Copy both. net.TCPConn implements io.ReaderFrom using the splice(2) syscall, which makes this much more efficient (everything happens in kernel space).

A working patch:

--- sniproxy.go.orig 2022-10-17 10:28:24.851394840 +0000 +++ sniproxy.go 2022-10-17 10:30:02.661635510 +0000 @@ -57,7 +57,7 @@ if err != nil { return nil, nil, err } - return hello, io.MultiReader(peekedBytes, reader), nil + return hello, peekedBytes, nil } type readOnlyConn struct { @@ -99,7 +99,7 @@ return } - clientHello, clientReader, err := peekClientHello(clientConn) + clientHello, clientHelloBytes, err := peekClientHello(clientConn) if err != nil { log.Print(err) return @@ -131,7 +131,8 @@ wg.Done() }() go func() { - io.Copy(backendConn, clientReader) + io.Copy(backendConn, clientHelloBytes) + io.Copy(backendConn, clientConn) backendConn.(*net.TCPConn).CloseWrite() wg.Done() }()

Reply

Post a Reply

Your comment will be public. To contact me privately, email me. Please keep your comment polite, on-topic, and comprehensible. Your comment may be held for moderation before being published.

(Optional; will be published)

(Optional; will not be published)

(Optional; will be published)

  • Blank lines separate paragraphs.
  • Lines starting with > are indented as block quotes.
  • Lines starting with two spaces are reproduced verbatim (good for code).
  • Text surrounded by *asterisks* is italicized.
  • Text surrounded by `back ticks` is monospaced.
  • URLs are turned into links.
  • Use the Preview button to check your formatting.