mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-24 11:55:40 +00:00
Merge pull request #13 from syncthing/timeout
Expose timeouts in protocol
This commit is contained in:
commit
95e15c95f2
14
protocol.go
14
protocol.go
@ -140,9 +140,9 @@ type isEofer interface {
|
|||||||
IsEOF() bool
|
IsEOF() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
var (
|
||||||
pingTimeout = 30 * time.Second
|
PingTimeout = 30 * time.Second
|
||||||
pingIdleTime = 60 * time.Second
|
PingIdleTime = 60 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewConnection(deviceID DeviceID, reader io.Reader, writer io.Writer, receiver Model, name string, compress Compression) Connection {
|
func NewConnection(deviceID DeviceID, reader io.Reader, writer io.Writer, receiver Model, name string, compress Compression) Connection {
|
||||||
@ -684,17 +684,17 @@ func (c *rawConnection) idGenerator() {
|
|||||||
|
|
||||||
func (c *rawConnection) pingerLoop() {
|
func (c *rawConnection) pingerLoop() {
|
||||||
var rc = make(chan bool, 1)
|
var rc = make(chan bool, 1)
|
||||||
ticker := time.Tick(pingIdleTime / 2)
|
ticker := time.Tick(PingIdleTime / 2)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker:
|
case <-ticker:
|
||||||
if d := time.Since(c.cr.Last()); d < pingIdleTime {
|
if d := time.Since(c.cr.Last()); d < PingIdleTime {
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugln(c.id, "ping skipped after rd", d)
|
l.Debugln(c.id, "ping skipped after rd", d)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if d := time.Since(c.cw.Last()); d < pingIdleTime {
|
if d := time.Since(c.cw.Last()); d < PingIdleTime {
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugln(c.id, "ping skipped after wr", d)
|
l.Debugln(c.id, "ping skipped after wr", d)
|
||||||
}
|
}
|
||||||
@ -714,7 +714,7 @@ func (c *rawConnection) pingerLoop() {
|
|||||||
if !ok {
|
if !ok {
|
||||||
c.close(fmt.Errorf("ping failure"))
|
c.close(fmt.Errorf("ping failure"))
|
||||||
}
|
}
|
||||||
case <-time.After(pingTimeout):
|
case <-time.After(PingTimeout):
|
||||||
c.close(fmt.Errorf("ping timeout"))
|
c.close(fmt.Errorf("ping timeout"))
|
||||||
case <-c.closed:
|
case <-c.closed:
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user