MCPcopy
hub / github.com/syncthing/syncthing / Close

Method Close

lib/protocol/protocol.go:941–962  ·  view source on GitHub ↗

Close is called when the connection is regularly closed and thus the Close BEP message is sent before terminating the actual connection. The error argument specifies the reason for closing the connection.

(err error)

Source from the content-addressed store, hash-verified

939// BEP message is sent before terminating the actual connection. The error
940// argument specifies the reason for closing the connection.
941func (c *rawConnection) Close(err error) {
942 c.sendCloseOnce.Do(func() {
943 done := make(chan struct{})
944 timeout := time.NewTimer(CloseTimeout)
945 select {
946 case c.closeBox <- asyncMessage{&bep.Close{Reason: err.Error()}, done}:
947 select {
948 case <-done:
949 case <-timeout.C:
950 case <-c.closed:
951 }
952 case <-timeout.C:
953 case <-c.closed:
954 }
955 })
956
957 // Close might be called from a method that is called from within
958 // dispatcherLoop, resulting in a deadlock.
959 // The sending above must happen before spawning the routine, to prevent
960 // the underlying connection from terminating before sending the close msg.
961 go c.internalClose(err)
962}
963
964// internalClose is called if there is an unexpected error during normal operation.
965func (c *rawConnection) internalClose(err error) {

Callers 1

StartMethod · 0.95

Calls 3

internalCloseMethod · 0.95
DoMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected