Skip to content

Commit

Permalink
set timeout before write
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Oct 23, 2024
1 parent 01e0982 commit 905a819
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ func (c *Client) exchange(ctx context.Context, req, resp *Message) error {
return err
}

_, err = conn.Write(req.Raw)
if err != nil {
return nil
}

if c.Timeout > 0 {
err = conn.SetDeadline(time.Now().Add(c.Timeout))
if err != nil {
return err
}
}

_, err = conn.Write(req.Raw)
if err != nil {
return nil
}

resp.Raw = resp.Raw[:cap(resp.Raw)]
n, err := conn.Read(resp.Raw)
if err != nil {
Expand Down

0 comments on commit 905a819

Please sign in to comment.