NewServer creates a gRPC server which has no service registered and has not started to accept requests yet.
(opt ...ServerOption)
| 702 | // NewServer creates a gRPC server which has no service registered and has not |
| 703 | // started to accept requests yet. |
| 704 | func NewServer(opt ...ServerOption) *Server { |
| 705 | opts := defaultServerOptions |
| 706 | for _, o := range globalServerOptions { |
| 707 | o.apply(&opts) |
| 708 | } |
| 709 | for _, o := range opt { |
| 710 | o.apply(&opts) |
| 711 | } |
| 712 | s := &Server{ |
| 713 | lis: make(map[net.Listener]bool), |
| 714 | opts: opts, |
| 715 | statsHandler: istats.NewCombinedHandler(opts.statsHandlers...), |
| 716 | conns: make(map[string]map[transport.ServerTransport]bool), |
| 717 | services: make(map[string]*serviceInfo), |
| 718 | quit: grpcsync.NewEvent(), |
| 719 | done: grpcsync.NewEvent(), |
| 720 | channelz: channelz.RegisterServer(""), |
| 721 | } |
| 722 | chainUnaryServerInterceptors(s) |
| 723 | chainStreamServerInterceptors(s) |
| 724 | s.cv = sync.NewCond(&s.mu) |
| 725 | if EnableTracing { |
| 726 | _, file, line, _ := runtime.Caller(1) |
| 727 | s.events = newTraceEventLog("grpc.Server", fmt.Sprintf("%s:%d", file, line)) |
| 728 | } |
| 729 | |
| 730 | if s.opts.numServerWorkers > 0 { |
| 731 | s.initServerWorkers() |
| 732 | } |
| 733 | |
| 734 | channelz.Info(logger, s.channelz, "Server created") |
| 735 | return s |
| 736 | } |
| 737 | |
| 738 | // printf records an event in s's event log, unless s has been stopped. |
| 739 | // REQUIRES s.mu is held. |