Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve rxStream performance using bufio reader #188

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/tap/protocol.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tap

import "encoding/binary"
import (
"encoding/binary"
)

type protocol interface {
Stream() bool
Expand Down
6 changes: 4 additions & 2 deletions pkg/tap/switch.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tap

import (
"bufio"
"context"
"io"
"net"
Expand Down Expand Up @@ -220,6 +221,7 @@ loop:
}

func (e *Switch) rxStream(ctx context.Context, id int, conn net.Conn, sProtocol streamProtocol) error {
reader := bufio.NewReader(conn)
sizeBuf := sProtocol.Buf()
loop:
for {
Expand All @@ -229,14 +231,14 @@ loop:
default:
// passthrough
}
_, err := io.ReadFull(conn, sizeBuf)
_, err := io.ReadFull(reader, sizeBuf)
if err != nil {
return errors.Wrap(err, "cannot read size from socket")
}
size := sProtocol.Read(sizeBuf)

buf := make([]byte, size)
_, err = io.ReadFull(conn, buf)
_, err = io.ReadFull(reader, buf)
if err != nil {
return errors.Wrap(err, "cannot read packet from socket")
}
Expand Down