summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-sql-driver/mysql/buffer.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-09-23 10:17:51 -0400
committerGitHub <noreply@github.com>2016-09-23 10:17:51 -0400
commit2ca0e8f9a0f9863555a26e984cde15efff9ef8f8 (patch)
treedaae1ee67b14a3d0a84424f2a304885d9e75ce2b /vendor/github.com/go-sql-driver/mysql/buffer.go
parent6d62d65b2dc85855aabea036cbd44f6059e19d13 (diff)
downloadchat-2ca0e8f9a0f9863555a26e984cde15efff9ef8f8.tar.gz
chat-2ca0e8f9a0f9863555a26e984cde15efff9ef8f8.tar.bz2
chat-2ca0e8f9a0f9863555a26e984cde15efff9ef8f8.zip
Updating golang dependancies (#4075)
Diffstat (limited to 'vendor/github.com/go-sql-driver/mysql/buffer.go')
-rw-r--r--vendor/github.com/go-sql-driver/mysql/buffer.go55
1 files changed, 17 insertions, 38 deletions
diff --git a/vendor/github.com/go-sql-driver/mysql/buffer.go b/vendor/github.com/go-sql-driver/mysql/buffer.go
index 2001feacd..794ac3099 100644
--- a/vendor/github.com/go-sql-driver/mysql/buffer.go
+++ b/vendor/github.com/go-sql-driver/mysql/buffer.go
@@ -8,11 +8,7 @@
package mysql
-import (
- "io"
- "net"
- "time"
-)
+import "io"
const defaultBufSize = 4096
@@ -22,28 +18,25 @@ const defaultBufSize = 4096
// The buffer is similar to bufio.Reader / Writer but zero-copy-ish
// Also highly optimized for this particular use case.
type buffer struct {
- buf []byte
- nc net.Conn
- idx int
- length int
- timeout time.Duration
+ buf []byte
+ rd io.Reader
+ idx int
+ length int
}
-func newBuffer(nc net.Conn) buffer {
+func newBuffer(rd io.Reader) buffer {
var b [defaultBufSize]byte
return buffer{
buf: b[:],
- nc: nc,
+ rd: rd,
}
}
// fill reads into the buffer until at least _need_ bytes are in it
func (b *buffer) fill(need int) error {
- n := b.length
-
// move existing data to the beginning
- if n > 0 && b.idx > 0 {
- copy(b.buf[0:n], b.buf[b.idx:])
+ if b.length > 0 && b.idx > 0 {
+ copy(b.buf[0:b.length], b.buf[b.idx:])
}
// grow buffer if necessary
@@ -59,33 +52,19 @@ func (b *buffer) fill(need int) error {
b.idx = 0
for {
- if b.timeout > 0 {
- if err := b.nc.SetReadDeadline(time.Now().Add(b.timeout)); err != nil {
- return err
- }
- }
+ n, err := b.rd.Read(b.buf[b.length:])
+ b.length += n
- nn, err := b.nc.Read(b.buf[n:])
- n += nn
-
- switch err {
- case nil:
- if n < need {
+ if err == nil {
+ if b.length < need {
continue
}
- b.length = n
return nil
-
- case io.EOF:
- if n >= need {
- b.length = n
- return nil
- }
- return io.ErrUnexpectedEOF
-
- default:
- return err
}
+ if b.length >= need && err == io.EOF {
+ return nil
+ }
+ return err
}
}