close the server when leaving
This commit is contained in:
parent
ca35fd19db
commit
73068a9c1f
@ -11,8 +11,9 @@ import (
|
||||
"net/http"
|
||||
"net/netip"
|
||||
|
||||
"git.sunturtle.xyz/zephyr/chord/chord"
|
||||
"github.com/go-json-experiment/json"
|
||||
|
||||
"git.sunturtle.xyz/zephyr/chord/chord"
|
||||
)
|
||||
|
||||
type Node struct {
|
||||
@ -22,6 +23,9 @@ type Node struct {
|
||||
// TODO(branden): really we should have a client per peer so that we can
|
||||
// interchange protocols
|
||||
client chord.Client
|
||||
// l is the listener that the HTTP server serves.
|
||||
// When the server leaves, it closes the listener.
|
||||
l net.Listener
|
||||
}
|
||||
|
||||
// New creates an instance of a Chord network that responds on HTTP.
|
||||
@ -39,6 +43,7 @@ func New(l net.Listener, cl chord.Client, self *chord.Node) (*Node, error) {
|
||||
r := &Node{
|
||||
self: self,
|
||||
client: cl,
|
||||
l: l,
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
@ -165,4 +170,6 @@ func (n *Node) bye(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
n.self.Leave(p, s)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
// Close the listener so that the server will shut down.
|
||||
n.l.Close()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user