File tree 2 files changed +15
-0
lines changed
2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,15 @@ func (c *Conn) Close(code StatusCode, reason string) error {
102
102
return c .closeHandshake (code , reason )
103
103
}
104
104
105
+ // CloseNow closes the WebSocket connection without attempting a close handshake.
106
+ // Use When you do not want the overhead of the close handshake.
107
+ func (c * Conn ) CloseNow () (err error ) {
108
+ defer errd .Wrap (& err , "failed to close WebSocket" )
109
+
110
+ c .close (nil )
111
+ return c .closeErr
112
+ }
113
+
105
114
func (c * Conn ) closeHandshake (code StatusCode , reason string ) (err error ) {
106
115
defer errd .Wrap (& err , "failed to close WebSocket" )
107
116
Original file line number Diff line number Diff line change @@ -147,6 +147,12 @@ func (c *Conn) close(err error) {
147
147
if c .isClosed () {
148
148
return
149
149
}
150
+ if err == nil {
151
+ err = c .rwc .Close ()
152
+ if err == nil {
153
+ err = errors .New ("WebSocket closed abnormally" )
154
+ }
155
+ }
150
156
c .setCloseErrLocked (err )
151
157
close (c .closed )
152
158
runtime .SetFinalizer (c , nil )
You can’t perform that action at this time.
0 commit comments