Skip to content

Commit

Permalink
set read/write at same time
Browse files Browse the repository at this point in the history
  • Loading branch information
isayme committed May 15, 2024
1 parent 39882e8 commit 5a56fee
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewTimeoutConn(conn net.Conn, timeout time.Duration) *timeoutConn {

func (c *timeoutConn) Read(p []byte) (n int, err error) {
if c.timeout > 0 {
if err := c.Conn.SetReadDeadline(time.Now().Add(c.timeout)); err != nil {
if err := c.Conn.SetDeadline(time.Now().Add(c.timeout)); err != nil {
return 0, err
}
}
Expand All @@ -31,7 +31,7 @@ func (c *timeoutConn) Read(p []byte) (n int, err error) {

func (c *timeoutConn) Write(p []byte) (n int, err error) {
if c.timeout > 0 {
if err := c.Conn.SetWriteDeadline(time.Now().Add(c.timeout)); err != nil {
if err := c.Conn.SetDeadline(time.Now().Add(c.timeout)); err != nil {
return 0, err
}
}
Expand Down

0 comments on commit 5a56fee

Please sign in to comment.