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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
websocket
Commits
e9dfcc4e
Unverified
Commit
e9dfcc4e
authored
5 years ago
by
Anmol Sethi
Browse files
Options
Downloads
Patches
Plain Diff
Improve Close UX
Closes #78
parent
4a611672
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
websocket.go
+9
-5
9 additions, 5 deletions
websocket.go
with
9 additions
and
5 deletions
websocket.go
+
9
−
5
View file @
e9dfcc4e
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"context"
"context"
"fmt"
"fmt"
"io"
"io"
"os"
"runtime"
"runtime"
"sync"
"sync"
"sync/atomic"
"sync/atomic"
...
@@ -353,6 +354,12 @@ func (c *Conn) writePong(p []byte) error {
...
@@ -353,6 +354,12 @@ func (c *Conn) writePong(p []byte) error {
// Close closes the WebSocket connection with the given status code and reason.
// Close closes the WebSocket connection with the given status code and reason.
// It will write a WebSocket close frame with a timeout of 5 seconds.
// It will write a WebSocket close frame with a timeout of 5 seconds.
// The connection can only be closed once. Additional calls to Close
// are no-ops.
// The maximum length of reason must be 125 bytes otherwise an internal
// error will be sent to the peer. For this reason, you should avoid
// sending a dynamic reason.
// Close will unblock all goroutines interacting with the connection.
func
(
c
*
Conn
)
Close
(
code
StatusCode
,
reason
string
)
error
{
func
(
c
*
Conn
)
Close
(
code
StatusCode
,
reason
string
)
error
{
err
:=
c
.
exportedClose
(
code
,
reason
)
err
:=
c
.
exportedClose
(
code
,
reason
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -372,17 +379,14 @@ func (c *Conn) exportedClose(code StatusCode, reason string) error {
...
@@ -372,17 +379,14 @@ func (c *Conn) exportedClose(code StatusCode, reason string) error {
// Definitely worth seeing what popular browsers do later.
// Definitely worth seeing what popular browsers do later.
p
,
err
:=
ce
.
bytes
()
p
,
err
:=
ce
.
bytes
()
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"failed to marshal close frame: %v
\n
"
,
err
)
ce
=
CloseError
{
ce
=
CloseError
{
Code
:
StatusInternalError
,
Code
:
StatusInternalError
,
}
}
p
,
_
=
ce
.
bytes
()
p
,
_
=
ce
.
bytes
()
}
}
cerr
:=
c
.
writeClose
(
p
,
ce
)
return
c
.
writeClose
(
p
,
ce
)
if
err
!=
nil
{
return
err
}
return
cerr
}
}
func
(
c
*
Conn
)
writeClose
(
p
[]
byte
,
cerr
CloseError
)
error
{
func
(
c
*
Conn
)
writeClose
(
p
[]
byte
,
cerr
CloseError
)
error
{
...
...
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