2016-02-26 17:35:57 -06:00
|
|
|
/*
|
|
|
|
Copyright 2016 gtalent2@gmail.com
|
|
|
|
|
|
|
|
This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
2016-02-15 00:18:56 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2016-02-29 00:06:31 -06:00
|
|
|
func setupService(serverManager *ServerManager, port int) {
|
2016-02-15 00:18:56 -06:00
|
|
|
portStr := strconv.Itoa(port)
|
|
|
|
addr, err := net.ResolveTCPAddr("tcp", "0.0.0.0:"+portStr)
|
|
|
|
if err != nil {
|
|
|
|
log.Print("Could not resolve port and listen address:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// listen on port
|
|
|
|
go func() {
|
|
|
|
l, err := net.ListenTCP("tcp", addr)
|
|
|
|
if err != nil {
|
|
|
|
log.Print("Could not listen for TCP connection:", err)
|
|
|
|
} else {
|
|
|
|
for {
|
|
|
|
conn, err := l.AcceptTCP()
|
|
|
|
if err != nil {
|
|
|
|
log.Print("Could not accept TCP connection:", err)
|
|
|
|
} else {
|
|
|
|
// connection accepted
|
|
|
|
|
|
|
|
// spinup machine
|
2016-02-29 00:06:31 -06:00
|
|
|
serverManager.Spinup()
|
2016-02-15 00:18:56 -06:00
|
|
|
|
|
|
|
// close existing connection, not doing anything with it
|
|
|
|
conn.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|