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)
| 939 | // BEP message is sent before terminating the actual connection. The error |
| 940 | // argument specifies the reason for closing the connection. |
| 941 | func (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. |
| 965 | func (c *rawConnection) internalClose(err error) { |
no test coverage detected