Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Commit

Permalink
fixed validate open function
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Solender committed Feb 23, 2020
1 parent 2da40c5 commit ceda19f
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func (c *Connection) sendInit(message structures.Structure) error {
}

func (c *Connection) ValidateOpen() bool {
log.Tracef("checking validate open")
if c.closed {
return false
}
Expand All @@ -311,20 +312,15 @@ func (c *Connection) ValidateOpen() bool {
return false
}

notify := make(chan error, 1)
buf := make([]byte, 1024)

_, err := c.readWrite.Read(buf)
one := make([]byte, 1)
err := c.conn.SetReadDeadline(time.Now())
if err != nil {
notify <- err
return false
}


select {
case <-time.After(time.Millisecond * 1):
return true
case <- notify:
if _, err := c.conn.Read(one); err == io.EOF {
return false
} else {
return true
}
}

Expand Down

0 comments on commit ceda19f

Please sign in to comment.