good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
websocket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
websocket
Commits
cdeb9806
Unverified
Commit
cdeb9806
authored
1 year ago
by
Anmol Sethi
Browse files
Options
Downloads
Patches
Plain Diff
ws_js.go: Add CloseNow
parent
25a5ca47
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc.go
+1
-0
1 addition, 0 deletions
doc.go
ws_js.go
+16
-7
16 additions, 7 deletions
ws_js.go
with
17 additions
and
7 deletions
doc.go
+
1
−
0
View file @
cdeb9806
...
...
@@ -28,6 +28,7 @@
//
// - Accept always errors out
// - Conn.Ping is no-op
// - Conn.CloseNow is Close(StatusGoingAway, "")
// - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
// - *http.Response from Dial is &http.Response{} with a 101 status code on success
package
websocket
// import "nhooyr.io/websocket"
This diff is collapsed.
Click to expand it.
ws_js.go
+
16
−
7
View file @
cdeb9806
...
...
@@ -151,7 +151,7 @@ func (c *Conn) read(ctx context.Context) (MessageType, []byte, error) {
return
0
,
nil
,
ctx
.
Err
()
case
<-
c
.
readSignal
:
case
<-
c
.
closed
:
return
0
,
nil
,
c
.
c
lose
Err
return
0
,
nil
,
errC
lose
d
}
c
.
readBufMu
.
Lock
()
...
...
@@ -205,7 +205,7 @@ func (c *Conn) Write(ctx context.Context, typ MessageType, p []byte) error {
func
(
c
*
Conn
)
write
(
ctx
context
.
Context
,
typ
MessageType
,
p
[]
byte
)
error
{
if
c
.
isClosed
()
{
return
c
.
c
lose
Err
return
errC
lose
d
}
switch
typ
{
case
MessageBinary
:
...
...
@@ -229,19 +229,28 @@ func (c *Conn) Close(code StatusCode, reason string) error {
return
nil
}
// CloseNow closes the WebSocket connection without attempting a close handshake.
// Use When you do not want the overhead of the close handshake.
//
// note: No different from Close(StatusGoingAway, "") in WASM as there is no way to close
// a WebSocket without the close handshake.
func
(
c
*
Conn
)
CloseNow
()
error
{
return
c
.
Close
(
StatusGoingAway
,
""
)
}
func
(
c
*
Conn
)
exportedClose
(
code
StatusCode
,
reason
string
)
error
{
c
.
closingMu
.
Lock
()
defer
c
.
closingMu
.
Unlock
()
if
c
.
isClosed
()
{
return
errClosed
}
ce
:=
fmt
.
Errorf
(
"sent close: %w"
,
CloseError
{
Code
:
code
,
Reason
:
reason
,
})
if
c
.
isClosed
()
{
return
fmt
.
Errorf
(
"tried to close with %q but connection already closed: %w"
,
ce
,
c
.
closeErr
)
}
c
.
setCloseErr
(
ce
)
err
:=
c
.
ws
.
Close
(
int
(
code
),
reason
)
if
err
!=
nil
{
...
...
@@ -312,7 +321,7 @@ func dial(ctx context.Context, url string, opts *DialOptions) (*Conn, *http.Resp
StatusCode
:
http
.
StatusSwitchingProtocols
,
},
nil
case
<-
c
.
closed
:
return
nil
,
nil
,
c
.
c
lose
Err
return
nil
,
nil
,
errC
lose
d
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment