Skip to content
Draft
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
14 changes: 7 additions & 7 deletions internal/conn/conn.go → internal/network/conn.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Package conn provides a TCP connection wrapper that adds preread functionality.
// Package network provides a TCP connection wrapper that adds preread functionality.
// During the preread phase, the read operations are recorded and can be reverted
// using the Rewind function and the same data can be read again from the beginning.
package conn
package network

import (
"errors"
Expand All @@ -23,7 +23,7 @@ type ConnMetrics interface {
}

type Conn struct {
*net.TCPConn
net.Conn

prereadLimit int
prereadEnd atomic.Bool
Expand All @@ -43,7 +43,7 @@ type Conn struct {
}

func (c *Conn) read(b []byte) (n int, err error) {
n, err = c.TCPConn.Read(b)
n, err = c.Conn.Read(b)
if c.metrics != nil {
c.metrics.ObserveRead(n, err)
}
Expand Down Expand Up @@ -94,7 +94,7 @@ func (c *Conn) ReadFrom(r io.Reader) (n int64, err error) {
}

func (c *Conn) write(b []byte) (n int, err error) {
n, err = c.TCPConn.Write(b)
n, err = c.Conn.Write(b)
if c.metrics != nil {
c.metrics.ObserveWrite(n, err)
}
Expand Down Expand Up @@ -167,9 +167,9 @@ func WithMetrics(m ConnMetrics) Option {

// New wraps the input TCP connection and returns a connection started in the
// preread phase.
func New(c *net.TCPConn, options ...Option) *Conn {
func New(c net.Conn, options ...Option) *Conn {
conn := &Conn{
TCPConn: c,
Conn: c,
prereadLimit: defaultPrereadLimit,
}
for _, option := range options {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package conn
package network

import (
"bytes"
Expand Down Expand Up @@ -1100,7 +1100,7 @@ func TestNewConnDefaults(t *testing.T) {
if conn.prereadCursor != 0 || conn.prereadBuf != nil {
t.Fatal("preread state must start empty")
}
if conn.TCPConn != local {
if conn.Conn != local {
t.Fatal("TCPConn not wired through")
}
}
Expand Down
Loading
Loading