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
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
github
nhooyr
websocket
Commits
cdeb9806
Unverified
Commit
cdeb9806
authored
Oct 19, 2023
by
Anmol Sethi
Browse files
Options
Downloads
Patches
Plain Diff
ws_js.go: Add CloseNow
parent
25a5ca47
No related branches found
No related tags found
No related merge requests found
Changes
2
Show 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 @@
...
@@ -28,6 +28,7 @@
//
//
// - Accept always errors out
// - Accept always errors out
// - Conn.Ping is no-op
// - Conn.Ping is no-op
// - Conn.CloseNow is Close(StatusGoingAway, "")
// - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
// - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
// - *http.Response from Dial is &http.Response{} with a 101 status code on success
// - *http.Response from Dial is &http.Response{} with a 101 status code on success
package
websocket
// import "nhooyr.io/websocket"
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) {
...
@@ -151,7 +151,7 @@ func (c *Conn) read(ctx context.Context) (MessageType, []byte, error) {
return
0
,
nil
,
ctx
.
Err
()
return
0
,
nil
,
ctx
.
Err
()
case
<-
c
.
readSignal
:
case
<-
c
.
readSignal
:
case
<-
c
.
closed
:
case
<-
c
.
closed
:
return
0
,
nil
,
c
.
c
lose
Err
return
0
,
nil
,
errC
lose
d
}
}
c
.
readBufMu
.
Lock
()
c
.
readBufMu
.
Lock
()
...
@@ -205,7 +205,7 @@ func (c *Conn) Write(ctx context.Context, typ MessageType, p []byte) error {
...
@@ -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
{
func
(
c
*
Conn
)
write
(
ctx
context
.
Context
,
typ
MessageType
,
p
[]
byte
)
error
{
if
c
.
isClosed
()
{
if
c
.
isClosed
()
{
return
c
.
c
lose
Err
return
errC
lose
d
}
}
switch
typ
{
switch
typ
{
case
MessageBinary
:
case
MessageBinary
:
...
@@ -229,19 +229,28 @@ func (c *Conn) Close(code StatusCode, reason string) error {
...
@@ -229,19 +229,28 @@ func (c *Conn) Close(code StatusCode, reason string) error {
return
nil
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
{
func
(
c
*
Conn
)
exportedClose
(
code
StatusCode
,
reason
string
)
error
{
c
.
closingMu
.
Lock
()
c
.
closingMu
.
Lock
()
defer
c
.
closingMu
.
Unlock
()
defer
c
.
closingMu
.
Unlock
()
if
c
.
isClosed
()
{
return
errClosed
}
ce
:=
fmt
.
Errorf
(
"sent close: %w"
,
CloseError
{
ce
:=
fmt
.
Errorf
(
"sent close: %w"
,
CloseError
{
Code
:
code
,
Code
:
code
,
Reason
:
reason
,
Reason
:
reason
,
})
})
if
c
.
isClosed
()
{
return
fmt
.
Errorf
(
"tried to close with %q but connection already closed: %w"
,
ce
,
c
.
closeErr
)
}
c
.
setCloseErr
(
ce
)
c
.
setCloseErr
(
ce
)
err
:=
c
.
ws
.
Close
(
int
(
code
),
reason
)
err
:=
c
.
ws
.
Close
(
int
(
code
),
reason
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -312,7 +321,7 @@ func dial(ctx context.Context, url string, opts *DialOptions) (*Conn, *http.Resp
...
@@ -312,7 +321,7 @@ func dial(ctx context.Context, url string, opts *DialOptions) (*Conn, *http.Resp
StatusCode
:
http
.
StatusSwitchingProtocols
,
StatusCode
:
http
.
StatusSwitchingProtocols
,
},
nil
},
nil
case
<-
c
.
closed
:
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