lnd: make Ready signal for custom listeners

This allows the caller to know when lnd is ready to accept RPC calls,
which is inmportant for mobile applications where eveything happens in
process.
This commit is contained in:
Johan T. Halseth
2019-11-29 11:35:37 +01:00
parent d59aba35a0
commit dc6c040803
2 changed files with 38 additions and 18 deletions

View File

@@ -9,7 +9,6 @@ import (
"fmt"
"io"
"math"
"net"
"net/http"
"sort"
"strings"
@@ -456,7 +455,7 @@ type rpcServer struct {
// listeners is a list of listeners to use when starting the grpc
// server. We make it configurable such that the grpc server can listen
// on custom interfaces.
listeners []net.Listener
listeners []*ListenerWithSignal
// listenerCleanUp are a set of closures functions that will allow this
// main RPC server to clean up all the listening socket created for the
@@ -706,8 +705,11 @@ func (r *rpcServer) Start() error {
// With all the sub-servers started, we'll spin up the listeners for
// the main RPC server itself.
for _, lis := range r.listeners {
go func(lis net.Listener) {
go func(lis *ListenerWithSignal) {
rpcsLog.Infof("RPC server listening on %s", lis.Addr())
// Close the ready chan to indicate we are listening.
close(lis.Ready)
r.grpcServer.Serve(lis)
}(lis)
}