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
af22b35a
Commit
af22b35a
authored
Dec 10, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: MuxConn writes don't block the whole loop
parent
68e51de0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
5 deletions
+23
-5
packer/rpc/muxconn.go
packer/rpc/muxconn.go
+23
-5
No files found.
packer/rpc/muxconn.go
View file @
af22b35a
...
...
@@ -175,16 +175,29 @@ func (m *MuxConn) openStream(id uint32) (*Stream, error) {
// Create the stream object and channel where data will be sent to
dataR
,
dataW
:=
io
.
Pipe
()
writeCh
:=
make
(
chan
[]
byte
,
10
)
// Set the data channel so we can write to it.
stream
:=
&
Stream
{
id
:
id
,
mux
:
m
,
reader
:
dataR
,
writer
:
dataW
,
id
:
id
,
mux
:
m
,
reader
:
dataR
,
writer
:
dataW
,
writeCh
:
writeCh
,
}
stream
.
setState
(
streamStateClosed
)
// Start the goroutine that will read from the queue and write
// data out.
go
func
()
{
for
{
data
:=
<-
writeCh
if
_
,
err
:=
dataW
.
Write
(
data
);
err
!=
nil
{
return
}
}
}()
m
.
streams
[
id
]
=
stream
return
m
.
streams
[
id
],
nil
}
...
...
@@ -256,7 +269,11 @@ func (m *MuxConn) loop() {
case
muxPacketData
:
stream
.
mu
.
Lock
()
if
stream
.
state
==
streamStateEstablished
{
stream
.
writer
.
Write
(
data
)
select
{
case
stream
.
writeCh
<-
data
:
default
:
log
.
Printf
(
"[ERR] Failed to write data, buffer full: %d"
,
id
)
}
}
else
{
log
.
Printf
(
"[ERR] Data received for stream in state: %d"
,
stream
.
state
)
}
...
...
@@ -293,6 +310,7 @@ type Stream struct {
state
streamState
stateUpdated
time
.
Time
mu
sync
.
Mutex
writeCh
chan
<-
[]
byte
}
type
streamState
byte
...
...
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