refine warden server start

pull/385/head
renzheng.wang 5 years ago
parent d6a78697e7
commit 232419458d
  1. 21
      pkg/net/rpc/warden/server.go

@ -302,17 +302,10 @@ func (s *Server) RunUnix(file string) error {
// will panic if any error happend
// return server itself
func (s *Server) Start() (*Server, error) {
lis, err := net.Listen(s.conf.Network, s.conf.Addr)
_, err := s.startWithAddr()
if err != nil {
return nil, err
}
log.Info("warden: start grpc listen addr: %v", lis.Addr())
reflection.Register(s.server)
go func() {
if err := s.Serve(lis); err != nil {
panic(err)
}
}()
return s, nil
}
@ -321,10 +314,18 @@ func (s *Server) Start() (*Server, error) {
// return server itself and the actually listened address (if configured listen
// port is zero, the os will allocate an unused port)
func (s *Server) StartWithAddr() (*Server, net.Addr, error) {
lis, err := net.Listen(s.conf.Network, s.conf.Addr)
addr, err := s.startWithAddr()
if err != nil {
return nil, nil, err
}
return s, addr, nil
}
func (s *Server) startWithAddr() (net.Addr, error) {
lis, err := net.Listen(s.conf.Network, s.conf.Addr)
if err != nil {
return nil, err
}
log.Info("warden: start grpc listen addr: %v", lis.Addr())
reflection.Register(s.server)
go func() {
@ -332,7 +333,7 @@ func (s *Server) StartWithAddr() (*Server, net.Addr, error) {
panic(err)
}
}()
return s, lis.Addr(), nil
return lis.Addr(), nil
}
// Serve accepts incoming connections on the listener lis, creating a new

Loading…
Cancel
Save