mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 02:00:11 -08:00
upgrade go-ident
Fixes a socket leak (that doesn't seem to be affecting tilde.town?)
This commit is contained in:
parent
2013beb7c8
commit
3bd3c6a88a
4 changed files with 15 additions and 8 deletions
15
vendor/github.com/ergochat/go-ident/client.go
generated
vendored
15
vendor/github.com/ergochat/go-ident/client.go
generated
vendored
|
|
@ -38,6 +38,12 @@ func (e ProtocolError) Error() string {
|
|||
|
||||
// Query makes an Ident query, if timeout is >0 the query is timed out after that many seconds.
|
||||
func Query(ip string, portOnServer, portOnClient int, timeout time.Duration) (response Response, err error) {
|
||||
// if a timeout is set, respect it from the beginning of the query, including the dial time
|
||||
var deadline time.Time
|
||||
if timeout > 0 {
|
||||
deadline = time.Now().Add(timeout)
|
||||
}
|
||||
|
||||
var conn net.Conn
|
||||
if timeout > 0 {
|
||||
conn, err = net.DialTimeout("tcp", net.JoinHostPort(ip, "113"), timeout)
|
||||
|
|
@ -47,13 +53,12 @@ func Query(ip string, portOnServer, portOnClient int, timeout time.Duration) (re
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// stop the ident read after <timeout> seconds
|
||||
if timeout > 0 {
|
||||
conn.SetDeadline(time.Now().Add(timeout))
|
||||
}
|
||||
// if timeout is 0, `deadline` is the empty time.Time{} which means no deadline:
|
||||
conn.SetDeadline(deadline)
|
||||
|
||||
_, err = conn.Write([]byte(fmt.Sprintf("%d, %d", portOnClient, portOnServer) + "\r\n"))
|
||||
_, err = conn.Write([]byte(fmt.Sprintf("%d, %d\r\n", portOnClient, portOnServer)))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue