This changes things to rely on a plugin server that manages all connections made to the server. An optional handler can be passed into the server when the caller wants to do extra things with the connection. It is the caller's responsibility to close the server. When the server is closed, first all existing connections are closed (and new connections are prevented). Now the signal loop only needs to close the server and not deal with `net.Conn`'s directly (or double-indirects as the case was before this change). The socket, when present in the filesystem, is no longer unlinked eagerly, as reconnections require it to be present for the lifecycle of the plugin server. Co-authored-by: Bjorn Neergaard <bjorn.neergaard@docker.com> Signed-off-by: Brian Goff <cpuguy83@gmail.com> Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
21 lines
434 B
Go
21 lines
434 B
Go
//go:build windows || linux
|
|
|
|
package socket
|
|
|
|
import (
|
|
"net"
|
|
)
|
|
|
|
func listen(socketname string) (*net.UnixListener, error) {
|
|
// Create an abstract socket -- this socket can be opened by name, but is
|
|
// not present in the filesystem.
|
|
return net.ListenUnix("unix", &net.UnixAddr{
|
|
Name: "@" + socketname,
|
|
Net: "unix",
|
|
})
|
|
}
|
|
|
|
func unlink(listener *net.UnixListener) {
|
|
// Do nothing; the socket is not present in the filesystem.
|
|
}
|