Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
68e51de0
Commit
68e51de0
authored
Dec 10, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: MuxConn.NextId properly increments
parent
2ac629c9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
6 deletions
+19
-6
packer/rpc/muxconn.go
packer/rpc/muxconn.go
+6
-6
packer/rpc/muxconn_test.go
packer/rpc/muxconn_test.go
+13
-0
No files found.
packer/rpc/muxconn.go
View file @
68e51de0
...
...
@@ -72,7 +72,7 @@ func (m *MuxConn) Accept(id uint32) (io.ReadWriteCloser, error) {
stream
.
mu
.
Lock
()
if
stream
.
state
!=
streamStateSynRecv
&&
stream
.
state
!=
streamStateClosed
{
stream
.
mu
.
Unlock
()
return
nil
,
fmt
.
Errorf
(
"Stream
already open in bad state: %d"
,
stream
.
state
)
return
nil
,
fmt
.
Errorf
(
"Stream
%d already open in bad state: %d"
,
id
,
stream
.
state
)
}
if
stream
.
state
==
streamStateSynRecv
{
...
...
@@ -124,7 +124,7 @@ func (m *MuxConn) Dial(id uint32) (io.ReadWriteCloser, error) {
stream
.
mu
.
Lock
()
if
stream
.
state
!=
streamStateClosed
{
stream
.
mu
.
Unlock
()
return
nil
,
fmt
.
Errorf
(
"Stream
already open in bad state: %d"
,
stream
.
state
)
return
nil
,
fmt
.
Errorf
(
"Stream
%d already open in bad state: %d"
,
id
,
stream
.
state
)
}
// Open a connection
...
...
@@ -157,11 +157,11 @@ func (m *MuxConn) NextId() uint32 {
defer
m
.
mu
.
Unlock
()
for
{
if
_
,
ok
:=
m
.
streams
[
m
.
curId
];
!
ok
{
return
m
.
curId
}
result
:=
m
.
curId
m
.
curId
++
if
_
,
ok
:=
m
.
streams
[
result
];
!
ok
{
return
result
}
}
}
...
...
packer/rpc/muxconn_test.go
View file @
68e51de0
...
...
@@ -159,3 +159,16 @@ func TestMuxConn_serverClosesStreams(t *testing.T) {
t
.
Fatalf
(
"err: %s"
,
err
)
}
}
func
TestMuxConnNextId
(
t
*
testing
.
T
)
{
client
,
server
:=
testMux
(
t
)
defer
client
.
Close
()
defer
server
.
Close
()
a
:=
client
.
NextId
()
b
:=
client
.
NextId
()
if
a
!=
0
||
b
!=
1
{
t
.
Fatalf
(
"IDs should increment"
)
}
}
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