Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
71877e01
Commit
71877e01
authored
Jan 30, 2015
by
Brian Tiger Chow
Browse files
fix(mux) hold lock when reading default handler field
parent
6b1de9b8
Changes
1
Show whitespace changes
Inline
Side-by-side
protocol/mux.go
View file @
71877e01
...
@@ -24,11 +24,11 @@ type streamHandlerMap map[ID]inet.StreamHandler
...
@@ -24,11 +24,11 @@ type streamHandlerMap map[ID]inet.StreamHandler
// It contains the handlers for each protocol accepted.
// It contains the handlers for each protocol accepted.
// It dispatches handlers for streams opened by remote peers.
// It dispatches handlers for streams opened by remote peers.
type
Mux
struct
{
type
Mux
struct
{
// defaultHandler handles unknown protocols. Callers modify at your own risk.
defaultHandler
inet
.
StreamHandler
lock
sync
.
RWMutex
lock
sync
.
RWMutex
handlers
streamHandlerMap
handlers
streamHandlerMap
// defaultHandler handles unknown protocols. Callers modify at your own risk.
defaultHandler
inet
.
StreamHandler
}
}
func
NewMux
()
*
Mux
{
func
NewMux
()
*
Mux
{
...
@@ -59,8 +59,8 @@ func (m *Mux) readHeader(s io.Reader) (ID, inet.StreamHandler, error) {
...
@@ -59,8 +59,8 @@ func (m *Mux) readHeader(s io.Reader) (ID, inet.StreamHandler, error) {
// log.Debug("readHeader got:", p)
// log.Debug("readHeader got:", p)
m
.
lock
.
RLock
()
m
.
lock
.
RLock
()
defer
m
.
lock
.
RUnlock
()
h
,
found
:=
m
.
handlers
[
p
]
h
,
found
:=
m
.
handlers
[
p
]
m
.
lock
.
RUnlock
()
switch
{
switch
{
case
!
found
&&
m
.
defaultHandler
!=
nil
:
case
!
found
&&
m
.
defaultHandler
!=
nil
:
...
...
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