mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 07:12:27 +00:00
Ensure that we make progress on the read side of a connection
This commit is contained in:
parent
6d7b001b0b
commit
804cce7ba0
@ -177,6 +177,9 @@ func (c *Connection) Request(repo string, name string, offset int64, size int) (
|
|||||||
return nil, ErrClosed
|
return nil, ErrClosed
|
||||||
}
|
}
|
||||||
rc := make(chan asyncResult)
|
rc := make(chan asyncResult)
|
||||||
|
if _, ok := c.awaiting[c.nextID]; ok {
|
||||||
|
panic("id taken")
|
||||||
|
}
|
||||||
c.awaiting[c.nextID] = rc
|
c.awaiting[c.nextID] = rc
|
||||||
header{0, c.nextID, messageTypeRequest}.encodeXDR(c.xw)
|
header{0, c.nextID, messageTypeRequest}.encodeXDR(c.xw)
|
||||||
_, err := RequestMessage{repo, name, uint64(offset), uint32(size)}.encodeXDR(c.xw)
|
_, err := RequestMessage{repo, name, uint64(offset), uint32(size)}.encodeXDR(c.xw)
|
||||||
@ -312,15 +315,17 @@ loop:
|
|||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Lock()
|
go func(hdr header, err error) {
|
||||||
rc, ok := c.awaiting[hdr.msgID]
|
c.Lock()
|
||||||
delete(c.awaiting, hdr.msgID)
|
rc, ok := c.awaiting[hdr.msgID]
|
||||||
c.Unlock()
|
delete(c.awaiting, hdr.msgID)
|
||||||
|
c.Unlock()
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
rc <- asyncResult{data, c.xr.Error()}
|
rc <- asyncResult{data, err}
|
||||||
close(rc)
|
close(rc)
|
||||||
}
|
}
|
||||||
|
}(hdr, c.xr.Error())
|
||||||
|
|
||||||
case messageTypePing:
|
case messageTypePing:
|
||||||
c.Lock()
|
c.Lock()
|
||||||
|
Loading…
Reference in New Issue
Block a user