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
f79daa0b
Commit
f79daa0b
authored
Dec 10, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: edge-triggerd state changes for faster dial/accept
parent
d9f79b0e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
26 deletions
+44
-26
packer/rpc/muxconn.go
packer/rpc/muxconn.go
+44
-26
No files found.
packer/rpc/muxconn.go
View file @
f79daa0b
...
...
@@ -84,23 +84,25 @@ func (m *MuxConn) Accept(id uint32) (io.ReadWriteCloser, error) {
if
stream
.
state
!=
streamStateEstablished
{
// Go into the listening state
stream
.
setState
(
streamStateListen
)
// Register a state change listener to wait for changes
stateCh
:=
make
(
chan
streamState
,
10
)
stream
.
registerStateListener
(
stateCh
)
defer
func
()
{
stream
.
mu
.
Lock
()
defer
stream
.
mu
.
Unlock
()
stream
.
deregisterStateListener
(
stateCh
)
}()
stream
.
mu
.
Unlock
()
// Wait for the connection to establish
ACCEPT_ESTABLISH_LOOP
:
for
{
time
.
Sleep
(
50
*
time
.
Millisecond
)
stream
.
mu
.
Lock
()
switch
stream
.
state
{
state
:=
<-
stateCh
switch
state
{
case
streamStateListen
:
stream
.
mu
.
Unlock
()
case
streamStateClosed
:
// This can happen if it becomes established, some data is sent,
// and it closed all within the time period we wait above.
// This case will be fixed when we have edge-triggered checks.
fallthrough
case
streamStateEstablished
:
stream
.
mu
.
Unlock
()
break
ACCEPT_ESTABLISH_LOOP
default
:
defer
stream
.
mu
.
Unlock
()
...
...
@@ -137,23 +139,23 @@ func (m *MuxConn) Dial(id uint32) (io.ReadWriteCloser, error) {
return
nil
,
err
}
stream
.
setState
(
streamStateSynSent
)
// Register a state change listener to wait for changes
stateCh
:=
make
(
chan
streamState
,
10
)
stream
.
registerStateListener
(
stateCh
)
defer
func
()
{
stream
.
mu
.
Lock
()
defer
stream
.
mu
.
Unlock
()
stream
.
deregisterStateListener
(
stateCh
)
}()
stream
.
mu
.
Unlock
()
for
{
time
.
Sleep
(
50
*
time
.
Millisecond
)
stream
.
mu
.
Lock
()
switch
stream
.
state
{
state
:=
<-
stateCh
switch
state
{
case
streamStateSynSent
:
stream
.
mu
.
Unlock
()
case
streamStateClosed
:
// This can happen if it becomes established, some data is sent,
// and it closed all within the time period we wait above.
// This case will be fixed when we have edge-triggered checks.
fallthrough
case
streamStateCloseWait
:
fallthrough
case
streamStateEstablished
:
stream
.
mu
.
Unlock
()
return
stream
,
nil
default
:
defer
stream
.
mu
.
Unlock
()
...
...
@@ -203,10 +205,11 @@ func (m *MuxConn) openStream(id uint32) (*Stream, error) {
// Set the data channel so we can write to it.
stream
:=
&
Stream
{
id
:
id
,
mux
:
m
,
reader
:
dataR
,
writeCh
:
writeCh
,
id
:
id
,
mux
:
m
,
reader
:
dataR
,
writeCh
:
writeCh
,
stateChange
:
make
(
map
[
chan
<-
streamState
]
struct
{}),
}
stream
.
setState
(
streamStateClosed
)
...
...
@@ -364,6 +367,7 @@ type Stream struct {
mux
*
MuxConn
reader
io
.
Reader
state
streamState
stateChange
map
[
chan
<-
streamState
]
struct
{}
stateUpdated
time
.
Time
mu
sync
.
Mutex
writeCh
chan
<-
[]
byte
...
...
@@ -421,7 +425,21 @@ func (s *Stream) remoteClose() {
s
.
writeCh
<-
nil
}
func
(
s
*
Stream
)
registerStateListener
(
ch
chan
<-
streamState
)
{
s
.
stateChange
[
ch
]
=
struct
{}{}
}
func
(
s
*
Stream
)
deregisterStateListener
(
ch
chan
<-
streamState
)
{
delete
(
s
.
stateChange
,
ch
)
}
func
(
s
*
Stream
)
setState
(
state
streamState
)
{
s
.
state
=
state
s
.
stateUpdated
=
time
.
Now
()
.
UTC
()
for
ch
,
_
:=
range
s
.
stateChange
{
select
{
case
ch
<-
state
:
default
:
}
}
}
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