@@ -9,6 +9,7 @@ package topology
99import (
1010 "context"
1111 "crypto/tls"
12+ "encoding/binary"
1213 "errors"
1314 "fmt"
1415 "io"
@@ -472,10 +473,7 @@ func (c *connection) readWireMessage(ctx context.Context) ([]byte, error) {
472473
473474func (c * connection ) parseWmSizeBytes (wmSizeBytes [4 ]byte ) (int32 , error ) {
474475 // read the length as an int32
475- size := (int32 (wmSizeBytes [0 ])) |
476- (int32 (wmSizeBytes [1 ]) << 8 ) |
477- (int32 (wmSizeBytes [2 ]) << 16 ) |
478- (int32 (wmSizeBytes [3 ]) << 24 )
476+ size := int32 (binary .LittleEndian .Uint32 (wmSizeBytes [:]))
479477
480478 if size < 4 {
481479 return 0 , fmt .Errorf ("malformed message length: %d" , size )
@@ -506,7 +504,7 @@ func (c *connection) read(ctx context.Context) (bytesRead []byte, errMsg string,
506504 }
507505 }()
508506
509- needToWait := func (err error ) bool {
507+ isCSOTTimeout := func (err error ) bool {
510508 // If the error was a timeout error and CSOT is enabled, instead of
511509 // closing the connection mark it as awaiting response so the pool
512510 // can read the response before making it available to other
@@ -524,7 +522,7 @@ func (c *connection) read(ctx context.Context) (bytesRead []byte, errMsg string,
524522 // reading messages from an exhaust cursor.
525523 n , err := io .ReadFull (c .nc , sizeBuf [:])
526524 if err != nil {
527- if l := int32 (n ); l == 0 && needToWait (err ) {
525+ if l := int32 (n ); l == 0 && isCSOTTimeout (err ) {
528526 c .awaitRemainingBytes = & l
529527 }
530528 return nil , "incomplete read of message header" , err
@@ -540,7 +538,7 @@ func (c *connection) read(ctx context.Context) (bytesRead []byte, errMsg string,
540538 n , err = io .ReadFull (c .nc , dst [4 :])
541539 if err != nil {
542540 remainingBytes := size - 4 - int32 (n )
543- if remainingBytes > 0 && needToWait (err ) {
541+ if remainingBytes > 0 && isCSOTTimeout (err ) {
544542 c .awaitRemainingBytes = & remainingBytes
545543 }
546544 return dst , "incomplete read of full message" , err
0 commit comments