github.com/wulonghui/docker@v1.8.0-rc2/pkg/listenbuffer/README.md (about)

     1  # listenbuffer
     2  
     3  listenbuffer uses the kernel's listening backlog functionality to queue
     4  connections, allowing applications to start listening immediately and handle
     5  connections later. This is signaled by closing the activation channel passed to
     6  the constructor.
     7  
     8  The maximum amount of queued connections depends on the configuration of your
     9  kernel (typically called SOMAXXCON) and cannot be configured in Go with the
    10  net package. See `src/net/sock_platform.go` in the Go tree or consult your
    11  kernel's manual.
    12  
    13  	activator := make(chan struct{})
    14  	buffer, err := NewListenBuffer("tcp", "localhost:4000", activator)
    15  	if err != nil {
    16  		panic(err)
    17  	}
    18  
    19  	// will block until activator has been closed or is sent an event
    20  	client, err := buffer.Accept()
    21  
    22  Somewhere else in your application once it's been booted:
    23  
    24  	close(activator)
    25  
    26  `buffer.Accept()` will return the first client in the kernel listening queue, or
    27  continue to block until a client connects or an error occurs.