Former-commit-id: 5f55201d9f494efd3f2f4d92231ad8f271ce94e6
This commit is contained in:
Gerasimos (Makis) Maropoulos 2018-09-30 16:46:10 +03:00
parent b08df3a785
commit 21ab51bde7

View File

@ -2,6 +2,7 @@ package websocket
import (
"bytes"
"errors"
"io"
"net"
"strconv"
@ -580,7 +581,14 @@ func (c *connection) Wait() {
c.startReader()
}
// ErrAlreadyDisconnected can be reported on the `Connection#Disconnect` function whenever the caller tries to close the
// connection when it is already closed by the client or the caller previously.
var ErrAlreadyDisconnected = errors.New("already disconnected")
func (c *connection) Disconnect() error {
if c == nil || c.disconnected {
return ErrAlreadyDisconnected
}
return c.server.Disconnect(c.ID())
}