-
Notifications
You must be signed in to change notification settings - Fork 997
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
allow packet.Conn buffer size to be adjustable #892
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"math" | ||
"net" | ||
"reflect" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
@@ -73,6 +74,29 @@ func TestDriverOptions_ConnectTimeout(t *testing.T) { | |
conn.Close() | ||
} | ||
|
||
func TestDriverOptions_BufferSize(t *testing.T) { | ||
log.SetLevel(log.LevelDebug) | ||
srv := CreateMockServer(t) | ||
defer srv.Stop() | ||
|
||
SetDSNOptions(map[string]DriverOption{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. our application is already using |
||
"bufferSize": func(c *client.Conn, value string) error { | ||
var err error | ||
c.BufferSize, err = strconv.Atoi(value) | ||
return err | ||
}, | ||
}) | ||
|
||
conn, err := sql.Open("mysql", "[email protected]:3307/test?bufferSize=4096") | ||
require.NoError(t, err) | ||
|
||
rows, err := conn.QueryContext(context.TODO(), "select * from table;") | ||
require.NotNil(t, rows) | ||
require.NoError(t, err) | ||
|
||
conn.Close() | ||
} | ||
|
||
func TestDriverOptions_ReadTimeout(t *testing.T) { | ||
log.SetLevel(log.LevelDebug) | ||
srv := CreateMockServer(t) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,19 +53,23 @@ type Conn struct { | |
} | ||
|
||
func NewConn(conn net.Conn) *Conn { | ||
return NewBufferedConn(conn, 65536) // 64kb | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keeping this |
||
} | ||
|
||
func NewBufferedConn(conn net.Conn, bufferSize int) *Conn { | ||
c := new(Conn) | ||
c.Conn = conn | ||
|
||
c.br = bufio.NewReaderSize(c, 65536) // 64kb | ||
c.br = bufio.NewReaderSize(c, bufferSize) | ||
c.reader = c.br | ||
|
||
c.copyNBuf = make([]byte, DefaultBufferSize) | ||
|
||
return c | ||
} | ||
|
||
func NewConnWithTimeout(conn net.Conn, readTimeout, writeTimeout time.Duration) *Conn { | ||
c := NewConn(conn) | ||
func NewConnWithTimeout(conn net.Conn, readTimeout, writeTimeout time.Duration, bufferSize int) *Conn { | ||
c := NewBufferedConn(conn, bufferSize) | ||
c.readTimeout = readTimeout | ||
c.writeTimeout = writeTimeout | ||
return c | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
init the new packet
Conn
with the 64kb buffer size