Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-ws-transport
Commits
722bc5b8
Commit
722bc5b8
authored
Sep 17, 2019
by
Alex Browne
Committed by
Steven Allen
Sep 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a sync.Once in Conn.Close
parent
94d33548
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
16 deletions
+19
-16
conn_browser.go
conn_browser.go
+19
-16
No files found.
conn_browser.go
View file @
722bc5b8
...
...
@@ -26,18 +26,19 @@ var errConnectionClosed = errors.New("connection is closed")
// Conn implements net.Conn interface for WebSockets in js/wasm.
type
Conn
struct
{
js
.
Value
messageHandler
*
js
.
Func
closeHandler
*
js
.
Func
errorHandler
*
js
.
Func
mut
sync
.
Mutex
currDataMut
sync
.
RWMutex
currData
bytes
.
Buffer
closeOnce
sync
.
Once
closeSignal
chan
struct
{}
dataSignal
chan
struct
{}
localAddr
net
.
Addr
remoteAddr
net
.
Addr
firstErr
error
messageHandler
*
js
.
Func
closeHandler
*
js
.
Func
errorHandler
*
js
.
Func
mut
sync
.
Mutex
currDataMut
sync
.
RWMutex
currData
bytes
.
Buffer
closeOnce
sync
.
Once
closeSignalOnce
sync
.
Once
closeSignal
chan
struct
{}
dataSignal
chan
struct
{}
localAddr
net
.
Addr
remoteAddr
net
.
Addr
firstErr
error
}
// NewConn creates a Conn given a regular js/wasm WebSocket Conn.
...
...
@@ -126,14 +127,16 @@ func (c *Conn) Write(b []byte) (n int, err error) {
// close error, subsequent and concurrent calls will return nil.
// This method is thread-safe.
func
(
c
*
Conn
)
Close
()
error
{
c
.
signalClose
()
c
.
Call
(
"close"
)
c
.
releaseHandlers
()
c
.
closeOnce
.
Do
(
func
()
{
c
.
signalClose
()
c
.
Call
(
"close"
)
c
.
releaseHandlers
()
})
return
nil
}
func
(
c
*
Conn
)
signalClose
()
{
c
.
closeOnce
.
Do
(
func
()
{
c
.
close
Signal
Once
.
Do
(
func
()
{
close
(
c
.
closeSignal
)
})
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment