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
1de4bc28
Unverified
Commit
1de4bc28
authored
Jul 20, 2019
by
Anmol Sethi
Browse files
Options
Downloads
Patches
Plain Diff
Improve docs and implementation of NetConn
parent
e2d44e32
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
netconn.go
+15
-10
15 additions, 10 deletions
netconn.go
with
15 additions
and
10 deletions
netconn.go
+
15
−
10
View file @
1de4bc28
...
@@ -26,7 +26,8 @@ import (
...
@@ -26,7 +26,8 @@ import (
// different from most net.Conn implementations where only the
// different from most net.Conn implementations where only the
// reading/writing goroutines are interrupted but the connection is kept alive.
// reading/writing goroutines are interrupted but the connection is kept alive.
//
//
// The Addr methods will return a mock net.Addr.
// The Addr methods will return a mock net.Addr that returns "websocket" for Network
// and "websocket/unknown-addr" for String.
//
//
// A received StatusNormalClosure close frame will be translated to EOF when reading.
// A received StatusNormalClosure close frame will be translated to EOF when reading.
func
NetConn
(
c
*
Conn
)
net
.
Conn
{
func
NetConn
(
c
*
Conn
)
net
.
Conn
{
...
@@ -37,11 +38,15 @@ func NetConn(c *Conn) net.Conn {
...
@@ -37,11 +38,15 @@ func NetConn(c *Conn) net.Conn {
var
cancel
context
.
CancelFunc
var
cancel
context
.
CancelFunc
nc
.
writeContext
,
cancel
=
context
.
WithCancel
(
context
.
Background
())
nc
.
writeContext
,
cancel
=
context
.
WithCancel
(
context
.
Background
())
nc
.
writeTimer
=
time
.
AfterFunc
(
math
.
MaxInt64
,
cancel
)
nc
.
writeTimer
=
time
.
AfterFunc
(
math
.
MaxInt64
,
cancel
)
nc
.
writeTimer
.
Stop
()
if
!
nc
.
writeTimer
.
Stop
()
{
<-
nc
.
writeTimer
.
C
}
nc
.
readContext
,
cancel
=
context
.
WithCancel
(
context
.
Background
())
nc
.
readContext
,
cancel
=
context
.
WithCancel
(
context
.
Background
())
nc
.
readTimer
=
time
.
AfterFunc
(
math
.
MaxInt64
,
cancel
)
nc
.
readTimer
=
time
.
AfterFunc
(
math
.
MaxInt64
,
cancel
)
nc
.
readTimer
.
Stop
()
if
!
nc
.
readTimer
.
Stop
()
{
<-
nc
.
readTimer
.
C
}
return
nc
return
nc
}
}
...
@@ -103,23 +108,23 @@ func (c *netConn) Read(p []byte) (int, error) {
...
@@ -103,23 +108,23 @@ func (c *netConn) Read(p []byte) (int, error) {
return
n
,
err
return
n
,
err
}
}
type
unknown
Addr
struct
{
type
websocket
Addr
struct
{
}
}
func
(
a
unknown
Addr
)
Network
()
string
{
func
(
a
websocket
Addr
)
Network
()
string
{
return
"
unknown
"
return
"
websocket
"
}
}
func
(
a
unknown
Addr
)
String
()
string
{
func
(
a
websocket
Addr
)
String
()
string
{
return
"unknown"
return
"
websocket/
unknown
-addr
"
}
}
func
(
c
*
netConn
)
RemoteAddr
()
net
.
Addr
{
func
(
c
*
netConn
)
RemoteAddr
()
net
.
Addr
{
return
unknown
Addr
{}
return
websocket
Addr
{}
}
}
func
(
c
*
netConn
)
LocalAddr
()
net
.
Addr
{
func
(
c
*
netConn
)
LocalAddr
()
net
.
Addr
{
return
unknown
Addr
{}
return
websocket
Addr
{}
}
}
func
(
c
*
netConn
)
SetDeadline
(
t
time
.
Time
)
error
{
func
(
c
*
netConn
)
SetDeadline
(
t
time
.
Time
)
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