Set timeout and deadline in DownloadDCC

This commit is contained in:
Ken-Håvard Lieng 2020-05-20 08:38:18 +02:00
parent e33b9f05e4
commit 1abe280957
3 changed files with 3 additions and 4 deletions

View File

@ -58,6 +58,7 @@ func NewClient(nick, username string) *Client {
out: make(chan string, 32),
quit: make(chan struct{}),
reconnect: make(chan struct{}),
dialer: &net.Dialer{Timeout: 10 * time.Second},
recvBuf: make([]byte, 0, 4096),
backoff: &backoff.Backoff{
Min: 500 * time.Millisecond,

View File

@ -7,7 +7,6 @@ import (
"crypto/x509"
"errors"
"fmt"
"net"
"strings"
"time"
)
@ -29,7 +28,6 @@ func (c *Client) Connect(address string) {
c.Host = address[:idx]
}
c.Server = address
c.dialer = &net.Dialer{Timeout: 10 * time.Second}
c.connChange(false, nil)
go c.run()
@ -244,7 +242,6 @@ func (c *Client) recv() {
if c.HandleNickInUse != nil {
go c.writeNick(c.HandleNickInUse(msg.Params[1]))
}
}
c.Messages <- msg

View File

@ -56,7 +56,7 @@ func DownloadDCC(w io.Writer, pack *DCCSend, progress chan DownloadProgress) err
}
}
conn, err := net.Dial("tcp", net.JoinHostPort(pack.IP, pack.Port))
conn, err := net.DialTimeout("tcp", net.JoinHostPort(pack.IP, pack.Port), 10*time.Second)
if err != nil {
return err
}
@ -70,6 +70,7 @@ func DownloadDCC(w io.Writer, pack *DCCSend, progress chan DownloadProgress) err
prevUpdate := start
for {
conn.SetReadDeadline(time.Now().Add(10 * time.Second))
n, err := conn.Read(buf)
if err != nil {
if err != io.EOF {