MCPcopy
hub / github.com/coder/websocket / CloseNow

Method CloseNow

close.go:132–155  ·  view source on GitHub ↗

CloseNow closes the WebSocket connection without attempting a close handshake. Use when you do not want the overhead of the close handshake.

()

Source from the content-addressed store, hash-verified

130// CloseNow closes the WebSocket connection without attempting a close handshake.
131// Use when you do not want the overhead of the close handshake.
132func (c *Conn) CloseNow() (err error) {
133 defer errd.Wrap(&err, "failed to immediately close WebSocket")
134
135 if c.casClosing() {
136 err = c.waitGoroutines()
137 if err != nil {
138 return err
139 }
140 return net.ErrClosed
141 }
142 defer func() {
143 if errors.Is(err, net.ErrClosed) {
144 err = nil
145 }
146 }()
147
148 err = c.close()
149
150 err2 := c.waitGoroutines()
151 if err == nil && err2 != nil {
152 err = err2
153 }
154 return err
155}
156
157func (c *Conn) closeHandshake(code StatusCode, reason string) error {
158 err := c.writeClose(code, reason)

Callers 12

subscribeMethod · 0.95
TestConnFunction · 0.45
newConnTestFunction · 0.45
TestConcurrentClosePingFunction · 0.45
ExampleAcceptFunction · 0.45
ExampleDialFunction · 0.45
ExampleCloseStatusFunction · 0.45
Example_writeOnlyFunction · 0.45
ExampleConn_PingFunction · 0.45
TestAcceptFunction · 0.45
Test_verifyHostOverrideFunction · 0.45
ServeHTTPMethod · 0.45

Calls 4

casClosingMethod · 0.95
waitGoroutinesMethod · 0.95
closeMethod · 0.95
WrapFunction · 0.92

Tested by 10

TestConnFunction · 0.36
newConnTestFunction · 0.36
TestConcurrentClosePingFunction · 0.36
ExampleAcceptFunction · 0.36
ExampleDialFunction · 0.36
ExampleCloseStatusFunction · 0.36
Example_writeOnlyFunction · 0.36
ExampleConn_PingFunction · 0.36
TestAcceptFunction · 0.36
Test_verifyHostOverrideFunction · 0.36