Skip to content

Commit

Permalink
Add configurable read deadline
Browse files Browse the repository at this point in the history
  • Loading branch information
xylo04 committed Sep 12, 2024
1 parent ace37f5 commit f4d7861
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
const localhostAddr = "127.0.0.1"
const rigctldPort = 4532

var readDeadline = 100 * time.Millisecond

type Client struct {
ServerAddr net.Addr
conn *net.TCPConn
Expand Down Expand Up @@ -38,6 +40,10 @@ func ConnectTo(ipAddr net.IP, port uint) (Client, error) {
return Client{addr, conn}, nil
}

func SetReadDeadline(d time.Duration) {
readDeadline = d
}

func (s *Client) writeRead(send string) (string, error) {
_, err := s.conn.Write([]byte(send))
if err != nil {
Expand All @@ -47,8 +53,7 @@ func (s *Client) writeRead(send string) (string, error) {
reader := bufio.NewReader(s.conn)
var resp string
for {
// TODO: Should this be configurable?
err := s.conn.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
err := s.conn.SetReadDeadline(time.Now().Add(readDeadline))
if err != nil {
return "", err
}
Expand Down

0 comments on commit f4d7861

Please sign in to comment.