Set timeout and deadline in DownloadDCC
This commit is contained in:
parent
e33b9f05e4
commit
1abe280957
@ -58,6 +58,7 @@ func NewClient(nick, username string) *Client {
|
|||||||
out: make(chan string, 32),
|
out: make(chan string, 32),
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
reconnect: make(chan struct{}),
|
reconnect: make(chan struct{}),
|
||||||
|
dialer: &net.Dialer{Timeout: 10 * time.Second},
|
||||||
recvBuf: make([]byte, 0, 4096),
|
recvBuf: make([]byte, 0, 4096),
|
||||||
backoff: &backoff.Backoff{
|
backoff: &backoff.Backoff{
|
||||||
Min: 500 * time.Millisecond,
|
Min: 500 * time.Millisecond,
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -29,7 +28,6 @@ func (c *Client) Connect(address string) {
|
|||||||
c.Host = address[:idx]
|
c.Host = address[:idx]
|
||||||
}
|
}
|
||||||
c.Server = address
|
c.Server = address
|
||||||
c.dialer = &net.Dialer{Timeout: 10 * time.Second}
|
|
||||||
|
|
||||||
c.connChange(false, nil)
|
c.connChange(false, nil)
|
||||||
go c.run()
|
go c.run()
|
||||||
@ -244,7 +242,6 @@ func (c *Client) recv() {
|
|||||||
if c.HandleNickInUse != nil {
|
if c.HandleNickInUse != nil {
|
||||||
go c.writeNick(c.HandleNickInUse(msg.Params[1]))
|
go c.writeNick(c.HandleNickInUse(msg.Params[1]))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Messages <- msg
|
c.Messages <- msg
|
||||||
|
@ -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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -70,6 +70,7 @@ func DownloadDCC(w io.Writer, pack *DCCSend, progress chan DownloadProgress) err
|
|||||||
prevUpdate := start
|
prevUpdate := start
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
conn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||||
n, err := conn.Read(buf)
|
n, err := conn.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != io.EOF {
|
if err != io.EOF {
|
||||||
|
Loading…
Reference in New Issue
Block a user