2
0

Only store Conn's *bufio.Reader in msgReader

Confusing and redundant to have the same *bufio.Reader in msgReader
and Conn.
This commit is contained in:
Jack Christensen
2017-02-09 19:37:23 -06:00
parent 72b6d32e2f
commit b8fdc38fa8
2 changed files with 5 additions and 7 deletions
+4 -6
View File
@@ -61,9 +61,8 @@ func (cc *ConnConfig) networkAddress() (network, address string) {
// Use ConnPool to manage access to multiple database connections from multiple
// goroutines.
type Conn struct {
conn net.Conn // the underlying TCP or unix domain socket connection
lastActivityTime time.Time // the last time the connection was used
reader *bufio.Reader // buffered reader to improve read performance
conn net.Conn // the underlying TCP or unix domain socket connection
lastActivityTime time.Time // the last time the connection was used
wbuf [1024]byte
writeBuf WriteBuf
Pid int32 // backend pid
@@ -274,8 +273,7 @@ func (c *Conn) connect(config ConnConfig, network, address string, tlsConfig *tl
}
}
c.reader = bufio.NewReader(c.conn)
c.mr.reader = c.reader
c.mr.reader = bufio.NewReader(c.conn)
msg := newStartupMessage()
@@ -862,7 +860,7 @@ func (c *Conn) waitForNotification(deadline time.Time) (*Notification, error) {
}
// Wait until there is a byte available before continuing onto the normal msg reading path
_, err = c.reader.Peek(1)
_, err = c.mr.reader.Peek(1)
if err != nil {
c.conn.SetReadDeadline(zeroTime) // we can only return one error and we already have one -- so ignore possiple error from SetReadDeadline
if err, ok := err.(*net.OpError); ok && err.Timeout() {
+1 -1
View File
@@ -289,7 +289,7 @@ func (rc *ReplicationConn) WaitForReplicationMessage(timeout time.Duration) (r *
}
// Wait until there is a byte available before continuing onto the normal msg reading path
_, err = rc.c.reader.Peek(1)
_, err = rc.c.mr.reader.Peek(1)
if err != nil {
rc.c.conn.SetReadDeadline(zeroTime) // we can only return one error and we already have one -- so ignore possiple error from SetReadDeadline
if err, ok := err.(*net.OpError); ok && err.Timeout() {