Skip to content

Commit

Permalink
fix: keepalive can not closed
Browse files Browse the repository at this point in the history
  • Loading branch information
ashertz-dev committed Nov 18, 2021
1 parent 8bb3f95 commit c492364
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions ssh/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ type Conn struct {
}

func (c *Conn) Read(b []byte) (int, error) {
err := c.Conn.SetReadDeadline(time.Now().Add(c.ReadTimeout))
if err != nil {
return 0, err
if c.ReadTimeout > 0 {
err := c.Conn.SetReadDeadline(time.Now().Add(c.ReadTimeout))
if err != nil {
return 0, err
}
}

return c.Conn.Read(b)
}

func (c *Conn) Write(b []byte) (int, error) {
err := c.Conn.SetWriteDeadline(time.Now().Add(c.WriteTimeout))
if err != nil {
return 0, err
if c.ReadTimeout > 0 {
err := c.Conn.SetWriteDeadline(time.Now().Add(c.WriteTimeout))
if err != nil {
return 0, err
}
}

return c.Conn.Write(b)
}

Expand Down
2 changes: 1 addition & 1 deletion ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (c *Config) Validate() error {
}

if c.ServerAliveInterval <= 0 {
c.ServerAliveInterval = time.Second
c.ServerAliveInterval = 0
}

if c.ServerAliveCountMax <= 1 {
Expand Down

0 comments on commit c492364

Please sign in to comment.