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
5007b240
Commit
5007b240
authored
May 04, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Server opens a port in the given range
parent
dbe53602
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
26 deletions
+17
-26
packer/rpc/port.go
packer/rpc/port.go
+2
-2
packer/rpc/server.go
packer/rpc/server.go
+15
-24
No files found.
packer/rpc/port.go
View file @
5007b240
...
...
@@ -5,8 +5,8 @@ import (
"net"
)
var
portRangeMin
int
=
0
var
portRangeMax
int
=
0
var
portRangeMin
int
=
1000
0
var
portRangeMax
int
=
1100
0
// This sets the port range that the RPC stuff will use when creating
// new temporary servers. Some RPC calls require the creation of temporary
...
...
packer/rpc/server.go
View file @
5007b240
...
...
@@ -10,21 +10,23 @@ import (
// A Server is a Golang RPC server that has helper methods for automatically
// setting up the endpoints for Packer interfaces.
type
Server
struct
{
listener
net
.
Listener
server
*
rpc
.
Server
started
bool
doneChan
chan
bool
}
// Creates and returns a new Server.
func
NewServer
()
*
Server
{
return
&
Server
{
server
:
rpc
.
NewServer
(),
started
:
false
,
}
}
func
(
s
*
Server
)
Address
()
string
{
return
":2345"
if
s
.
listener
==
nil
{
panic
(
"Server not listening."
)
}
return
s
.
listener
.
Addr
()
.
String
()
}
func
(
s
*
Server
)
RegisterUi
(
ui
packer
.
Ui
)
{
...
...
@@ -32,29 +34,21 @@ func (s *Server) RegisterUi(ui packer.Ui) {
}
func
(
s
*
Server
)
Start
()
error
{
if
s
.
started
{
if
s
.
listener
!=
nil
{
return
errors
.
New
(
"Server already started."
)
}
// TODO: Address
address
:=
":2345"
// Mark that we started and setup the channel we'll use to mark exits
s
.
started
=
true
s
.
doneChan
=
make
(
chan
bool
)
// Start the TCP listener and a goroutine responsible for cleaning up the
// listener.
listener
,
_
:=
net
.
Listen
(
"tcp"
,
address
)
go
func
()
{
<-
s
.
doneChan
listener
.
Close
()
}()
s
.
listener
=
netListenerInRange
(
portRangeMin
,
portRangeMax
)
if
s
.
listener
==
nil
{
return
errors
.
New
(
"Could not open a port ot listen on."
)
}
// Start accepting connections
go
func
()
{
for
{
conn
,
err
:=
listener
.
Accept
()
conn
,
err
:=
s
.
listener
.
Accept
()
if
err
!=
nil
{
break
}
...
...
@@ -67,11 +61,8 @@ func (s *Server) Start() error {
}
func
(
s
*
Server
)
Stop
()
{
if
s
.
started
{
// TODO: There is a race condition here, we need to wait for
// the listener to REALLY close.
s
.
doneChan
<-
true
s
.
started
=
false
s
.
doneChan
=
nil
if
s
.
listener
!=
nil
{
s
.
listener
.
Close
()
s
.
listener
=
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