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
f6ca84ad
Commit
f6ca84ad
authored
Dec 17, 2019
by
vyzo
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add mutex for write/close
parent
3098bba5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
0 deletions
+7
-0
conn_native.go
conn_native.go
+7
-0
No files found.
conn_native.go
View file @
f6ca84ad
...
...
@@ -17,6 +17,7 @@ type Conn struct {
DefaultMessageType
int
reader
io
.
Reader
closeOnce
sync
.
Once
mx
sync
.
Mutex
}
func
(
c
*
Conn
)
Read
(
b
[]
byte
)
(
int
,
error
)
{
...
...
@@ -67,6 +68,9 @@ func (c *Conn) prepNextReader() error {
}
func
(
c
*
Conn
)
Write
(
b
[]
byte
)
(
n
int
,
err
error
)
{
c
.
mx
.
Lock
()
defer
c
.
mx
.
Unlock
()
if
err
:=
c
.
Conn
.
WriteMessage
(
c
.
DefaultMessageType
,
b
);
err
!=
nil
{
return
0
,
err
}
...
...
@@ -78,6 +82,9 @@ 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
.
mx
.
Lock
()
defer
c
.
mx
.
Unlock
()
var
err
error
c
.
closeOnce
.
Do
(
func
()
{
err1
:=
c
.
Conn
.
WriteControl
(
...
...
tavit ohanian
@tavit
mentioned in commit
82be3ddc
·
Jul 02, 2021
mentioned in commit
82be3ddc
mentioned in commit 82be3ddcd1c8e86c28414011901c493cac08dcae
Toggle commit list
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