proxy: add exposePort and unexposePort stubs

This patch removes `proxyForever` and adds `sendError` and `sendOK` for
signalling to the parent process. The main function now sequences these
functions and calls stub functions `exposePort` and `unexposePort` which
will be hooked up in a later patch.

Signed-off-by: David Scott <dave.scott@docker.com>
This commit is contained in:
David Scott 2016-04-03 14:57:35 +01:00
parent 3d5767714c
commit eab69ef583
2 changed files with 32 additions and 16 deletions

View File

@ -2,6 +2,7 @@ package main
import (
"log"
"net"
"os"
"pkg/proxy"
)
@ -9,10 +10,27 @@ import (
func main() {
host, container := parseHostContainerAddrs()
err := proxyForever(proxy.NewProxy(host, container))
err := exposePort(host)
if err != nil {
os.Exit(0)
sendError(err)
}
os.Exit(1)
p, err := proxy.NewProxy(host, container)
if err != nil {
unexposePort(host)
sendError(err)
}
go handleStopSignals(p)
sendOK()
p.Run()
unexposePort(host)
os.Exit(0)
}
func exposePort(host net.Addr) error {
log.Printf("exposePort %#v\n", host)
return nil
}
func unexposePort(host net.Addr) {
log.Printf("unexposePort %#v\n", host)
}

View File

@ -12,22 +12,20 @@ import (
"pkg/proxy"
)
// proxyForever signals the parent success/failure and runs the proxy forever
func proxyForever(p proxy.Proxy, err error) error {
// sendError signals the error to the parent and quits the process.
func sendError(err error) {
f := os.NewFile(3, "signal-parent")
if err != nil {
fmt.Fprintf(f, "1\n%s", err)
f.Close()
return err
}
go handleStopSignals(p)
fmt.Fprintf(f, "1\n%s", err)
f.Close()
os.Exit(1)
}
// sendOK signals the parent that the forward is running.
func sendOK() {
f := os.NewFile(3, "signal-parent")
fmt.Fprint(f, "0\n")
f.Close()
// Run will block until the proxy stops
p.Run()
return nil
}
// From docker/libnetwork/portmapper/proxy.go: