Browse code

Remove usage of listenbuffer package

It actually adds nothing to queuing requests.

Signed-off-by: Alexander Morozov <lk4d4@docker.com>

Alexander Morozov authored on 2015/11/26 04:05:31
Showing 5 changed files
... ...
@@ -39,7 +39,6 @@ type Config struct {
39 39
 // Server contains instance details for the server
40 40
 type Server struct {
41 41
 	cfg     *Config
42
-	start   chan struct{}
43 42
 	servers []*HTTPServer
44 43
 	routers []router.Router
45 44
 }
... ...
@@ -54,8 +53,7 @@ type Addr struct {
54 54
 // It allocates resources which will be needed for ServeAPI(ports, unix-sockets).
55 55
 func New(cfg *Config) (*Server, error) {
56 56
 	s := &Server{
57
-		cfg:   cfg,
58
-		start: make(chan struct{}),
57
+		cfg: cfg,
59 58
 	}
60 59
 	for _, addr := range cfg.Addrs {
61 60
 		srv, err := s.newServer(addr.Proto, addr.Addr)
... ...
@@ -132,7 +130,7 @@ func (s *Server) initTCPSocket(addr string) (l net.Listener, err error) {
132 132
 	if s.cfg.TLSConfig == nil || s.cfg.TLSConfig.ClientAuth != tls.RequireAndVerifyClientCert {
133 133
 		logrus.Warn("/!\\ DON'T BIND ON ANY IP ADDRESS WITHOUT setting -tlsverify IF YOU DON'T KNOW WHAT YOU'RE DOING /!\\")
134 134
 	}
135
-	if l, err = sockets.NewTCPSocket(addr, s.cfg.TLSConfig, s.start); err != nil {
135
+	if l, err = sockets.NewTCPSocket(addr, s.cfg.TLSConfig); err != nil {
136 136
 		return nil, err
137 137
 	}
138 138
 	if err := allocateDaemonPort(addr); err != nil {
... ...
@@ -202,15 +200,3 @@ func (s *Server) CreateMux() *mux.Router {
202 202
 
203 203
 	return m
204 204
 }
205
-
206
-// AcceptConnections allows clients to connect to the API server.
207
-// Referenced Daemon is notified about this server, and waits for the
208
-// daemon acknowledgement before the incoming connections are accepted.
209
-func (s *Server) AcceptConnections() {
210
-	// close the lock so the listeners start accepting connections
211
-	select {
212
-	case <-s.start:
213
-	default:
214
-		close(s.start)
215
-	}
216
-}
... ...
@@ -36,7 +36,7 @@ func (s *Server) newServer(proto, addr string) ([]*HTTPServer, error) {
36 36
 		}
37 37
 		ls = append(ls, l)
38 38
 	case "unix":
39
-		l, err := sockets.NewUnixSocket(addr, s.cfg.SocketGroup, s.start)
39
+		l, err := sockets.NewUnixSocket(addr, s.cfg.SocketGroup)
40 40
 		if err != nil {
41 41
 			return nil, err
42 42
 		}
... ...
@@ -268,10 +268,8 @@ func (cli *DaemonCli) CmdDaemon(args ...string) error {
268 268
 		}
269 269
 	})
270 270
 
271
-	// after the daemon is done setting up we can tell the api to start
272
-	// accepting connections with specified daemon
271
+	// after the daemon is done setting up we can notify systemd api
273 272
 	notifySystem()
274
-	api.AcceptConnections()
275 273
 
276 274
 	// Daemon is fully initialized and handling API traffic
277 275
 	// Wait for serve API to complete
... ...
@@ -7,17 +7,13 @@ import (
7 7
 	"net"
8 8
 	"net/http"
9 9
 	"time"
10
-
11
-	"github.com/docker/docker/pkg/listenbuffer"
12 10
 )
13 11
 
14 12
 // NewTCPSocket creates a TCP socket listener with the specified address and
15 13
 // and the specified tls configuration. If TLSConfig is set, will encapsulate the
16 14
 // TCP listener inside a TLS one.
17
-// The channel passed is used to activate the listenbuffer when the caller is ready
18
-// to accept connections.
19
-func NewTCPSocket(addr string, tlsConfig *tls.Config, activate <-chan struct{}) (net.Listener, error) {
20
-	l, err := listenbuffer.NewListenBuffer("tcp", addr, activate)
15
+func NewTCPSocket(addr string, tlsConfig *tls.Config) (net.Listener, error) {
16
+	l, err := net.Listen("tcp", addr)
21 17
 	if err != nil {
22 18
 		return nil, err
23 19
 	}
... ...
@@ -10,20 +10,17 @@ import (
10 10
 	"syscall"
11 11
 
12 12
 	"github.com/Sirupsen/logrus"
13
-	"github.com/docker/docker/pkg/listenbuffer"
14 13
 	"github.com/opencontainers/runc/libcontainer/user"
15 14
 )
16 15
 
17 16
 // NewUnixSocket creates a unix socket with the specified path and group.
18
-// The channel passed is used to activate the listenbuffer when the caller is ready
19
-// to accept connections.
20
-func NewUnixSocket(path, group string, activate <-chan struct{}) (net.Listener, error) {
17
+func NewUnixSocket(path, group string) (net.Listener, error) {
21 18
 	if err := syscall.Unlink(path); err != nil && !os.IsNotExist(err) {
22 19
 		return nil, err
23 20
 	}
24 21
 	mask := syscall.Umask(0777)
25 22
 	defer syscall.Umask(mask)
26
-	l, err := listenbuffer.NewListenBuffer("unix", path, activate)
23
+	l, err := net.Listen("unix", path)
27 24
 	if err != nil {
28 25
 		return nil, err
29 26
 	}