diff options
author | Hubert Hirtz <hubert@hirtz.pm> | 2021-05-17 22:40:09 +0200 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-05-17 22:40:09 +0200 |
commit | 4969650bde9ac3b8eb5be661abb601aeb5847bac (patch) | |
tree | ddcb2857684eed3a4c0e33fa942b75552dd1ee75 /app.go | |
parent | commands: ignore empty input (diff) |
Add port if missing (v2) and don't set keepalives
Diffstat (limited to 'app.go')
-rw-r--r-- | app.go | 31 |
1 files changed, 9 insertions, 22 deletions
@@ -168,38 +168,25 @@ func (app *App) connect() { func (app *App) tryConnect() (err error) { addr := app.cfg.Addr - host, port, err := net.SplitHostPort(addr) - if err != nil { - return err - } - if port == "" { + colonIdx := strings.LastIndexByte(addr, ':') + bracketIdx := strings.LastIndexByte(addr, ']') + if colonIdx <= bracketIdx { + // either colonIdx < 0, or the last colon is before a ']' (end + // of IPv6 address. -> missing port if app.cfg.NoTLS { - port = "6667" + addr += ":6667" } else { - port = "6697" + addr += ":6697" } } - peerAddr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(host, port)) - if err != nil { - return - } - - tcpConn, err := net.DialTCP("tcp", nil, peerAddr) + conn, err := net.Dial("tcp", addr) if err != nil { return } - if err = tcpConn.SetKeepAlivePeriod(1 * time.Minute); err != nil { - tcpConn.Close() - return - } - if err = tcpConn.SetKeepAlive(true); err != nil { - tcpConn.Close() - return - } - var conn net.Conn = tcpConn if !app.cfg.NoTLS { + host, _, _ := net.SplitHostPort(addr) // should succeed since net.Dial did. conn = tls.Client(conn, &tls.Config{ ServerName: host, NextProtos: []string{"irc"}, |