@@ -47,12 +47,20 @@ func (mc *mysqlConn) readPacket() (data []byte, e error) {
47
47
48
48
// Read rest of packet
49
49
data = make ([]byte , pktLen )
50
- n , e := mc .netConn .Read (data )
50
+ var n , add int
51
+ n , e = mc .netConn .Read (data )
52
+
53
+ // Read conventionally returns what is available instead of waiting for more
54
+ for e == nil && n < int (pktLen ) {
55
+ add , e = mc .netConn .Read (data [n :])
56
+ n += add
57
+ }
58
+
51
59
if e != nil || n != int (pktLen ) {
52
60
e = driver .ErrBadConn
53
61
return
54
62
}
55
- return
63
+ return data [: pktLen ], e // Return without scratch space
56
64
}
57
65
58
66
// Send Packet with given data
@@ -275,20 +283,20 @@ func (mc *mysqlConn) writeCommandPacket(command commandType, args ...interface{}
275
283
// Commands without args
276
284
case COM_QUIT , COM_PING :
277
285
if len (args ) > 0 {
278
- return fmt .Errorf ("Too much arguments (Got: %d Has:0)" , len (args ))
286
+ return fmt .Errorf ("Too much arguments (Got: %d Has: 0)" , len (args ))
279
287
}
280
288
281
289
// Commands with 1 arg unterminated string
282
290
case COM_QUERY , COM_STMT_PREPARE :
283
291
if len (args ) != 1 {
284
- return fmt .Errorf ("Invalid arguments count (Got:%d Need: 1)" , len (args ))
292
+ return fmt .Errorf ("Invalid arguments count (Got: %d Need: 1)" , len (args ))
285
293
}
286
294
data = append (data , []byte (args [0 ].(string ))... )
287
295
288
296
// Commands with 1 arg 32 bit uint
289
297
case COM_STMT_CLOSE :
290
298
if len (args ) != 1 {
291
- return fmt .Errorf ("Invalid arguments count (Got:%d Need: 1)" , len (args ))
299
+ return fmt .Errorf ("Invalid arguments count (Got: %d Need: 1)" , len (args ))
292
300
}
293
301
data = append (data , uint32ToBytes (args [0 ].(uint32 ))... )
294
302
default :
0 commit comments