aboutsummaryrefslogtreecommitdiff
path: root/hotline/handshake.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-06 19:41:07 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-06 19:41:07 -0700
commitd4c152a4dba0eec7c8ecd13732900909f51b1c97 (patch)
treecf1653bad283565ad3fe3f63c763e700f04ee363 /hotline/handshake.go
parentc26c20e3539233a6cde9e64aa9d9a89b2017a772 (diff)
Refactor and cleanup to improve testability
Diffstat (limited to 'hotline/handshake.go')
-rw-r--r--hotline/handshake.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/hotline/handshake.go b/hotline/handshake.go
index 66bf643..39d9cab 100644
--- a/hotline/handshake.go
+++ b/hotline/handshake.go
@@ -4,7 +4,7 @@ import (
"bytes"
"encoding/binary"
"errors"
- "net"
+ "io"
)
type handshake struct {
@@ -33,9 +33,14 @@ type handshake struct {
// Description Size Data Note
// Protocol ID 4 TRTP
// Error code 4 Error code returned by the server (0 = no error)
-func Handshake(conn net.Conn, buf []byte) error {
+func Handshake(conn io.ReadWriter) error {
+ handshakeBuf := make([]byte, 12)
+ if _, err := io.ReadFull(conn, handshakeBuf); err != nil {
+ return err
+ }
+
var h handshake
- r := bytes.NewReader(buf)
+ r := bytes.NewReader(handshakeBuf)
if err := binary.Read(r, binary.BigEndian, &h); err != nil {
return err
}