Commit 8cdc65ed authored by Matt Holt's avatar Matt Holt Committed by GitHub

Merge pull request #1048 from miekg/missingbits

Implement missing bits for an external servertype
parents fdc62d01 a609fa5f
......@@ -76,7 +76,7 @@ type Instance struct {
context Context
// servers is the list of servers with their listeners.
servers []serverListener
servers []ServerListener
// these callbacks execute when certain events occur
onFirstStartup []func() error // starting, not as part of a restart
......@@ -86,6 +86,9 @@ type Instance struct {
onFinalShutdown []func() error // stopping, not as part of a restart
}
// Servers returns the ServerListeners in i.
func (i *Instance) Servers() []ServerListener { return i.servers }
// Stop stops all servers contained in i. It does NOT
// execute shutdown callbacks.
func (i *Instance) Stop() error {
......@@ -202,7 +205,7 @@ func (i *Instance) Restart(newCaddyfile Input) (*Instance, error) {
// internally-kept list of servers that is running. For
// saved servers, graceful restarts will be provided.
func (i *Instance) SaveServer(s Server, ln net.Listener) {
i.servers = append(i.servers, serverListener{server: s, listener: ln})
i.servers = append(i.servers, ServerListener{server: s, listener: ln})
}
// HasListenerWithAddress returns whether this package is
......@@ -644,7 +647,7 @@ func startServers(serverList []Server, inst *Instance, restartFds map[string]res
errChan <- s.ServePacket(pc)
}(s, ln, pc, inst)
inst.servers = append(inst.servers, serverListener{server: s, listener: ln, packet: pc})
inst.servers = append(inst.servers, ServerListener{server: s, listener: ln, packet: pc})
}
// Log errors that may be returned from Serve() calls,
......@@ -836,7 +839,7 @@ var (
instancesMu sync.Mutex
)
const (
var (
// DefaultConfigFile is the name of the configuration file that is loaded
// by default if no other file is specified.
DefaultConfigFile = "Caddyfile"
......
......@@ -82,13 +82,31 @@ func ValidDirectives(serverType string) []string {
return stype.Directives
}
// serverListener pairs a server to its listener and/or packetconn.
type serverListener struct {
// ServerListener pairs a server to its listener and/or packetconn.
type ServerListener struct {
server Server
listener net.Listener
packet net.PacketConn
}
// LocalAddr returns the local network address of the packetconn. It returns
// nil when it is not set.
func (s ServerListener) LocalAddr() net.Addr {
if s.packet == nil {
return nil
}
return s.packet.LocalAddr()
}
// Addr returns the listener's network address. It returns nil when it is
// not set.
func (s ServerListener) Addr() net.Addr {
if s.listener == nil {
return nil
}
return s.listener.Addr()
}
// Context is a type which carries a server type through
// the load and setup phase; it maintains the state
// between loading the Caddyfile, then executing its
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment