MCPcopy Index your code
hub / github.com/coder/coder / Serve

Method Serve

agent/agentssh/agentssh.go:1044–1070  ·  view source on GitHub ↗

Serve starts the server to handle incoming connections on the provided listener. It returns an error if no host keys are set or if there is an issue accepting connections.

(l net.Listener)

Source from the content-addressed store, hash-verified

1042// Serve starts the server to handle incoming connections on the provided listener.
1043// It returns an error if no host keys are set or if there is an issue accepting connections.
1044func (s *Server) Serve(l net.Listener) (retErr error) {
1045 // Ensure we're not mutating HostSigners as we're reading it.
1046 s.mu.RLock()
1047 noHostKeys := len(s.srv.HostSigners) == 0
1048 s.mu.RUnlock()
1049
1050 if noHostKeys {
1051 return xerrors.New("no host keys set")
1052 }
1053
1054 s.logger.Info(context.Background(), "started serving listener", slog.F("listen_addr", l.Addr()))
1055 defer func() {
1056 s.logger.Info(context.Background(), "stopped serving listener",
1057 slog.F("listen_addr", l.Addr()), slog.Error(retErr))
1058 }()
1059 defer l.Close()
1060
1061 s.trackListener(l, true)
1062 defer s.trackListener(l, false)
1063 for {
1064 conn, err := l.Accept()
1065 if err != nil {
1066 return err
1067 }
1068 go s.handleConn(l, conn)
1069 }
1070}
1071
1072func (s *Server) handleConn(l net.Listener, c net.Conn) {
1073 logger := s.logger.With(

Callers 15

TestTunnelFunction · 0.95
serveTailnetHTTPFunction · 0.95
ServerMethod · 0.95
ServeHandlerFunction · 0.95
createTailnetMethod · 0.95
TestServer_X11Function · 0.95
TestNewServer_SignalFunction · 0.95

Calls 8

trackListenerMethod · 0.95
handleConnMethod · 0.95
NewMethod · 0.65
CloseMethod · 0.65
InfoMethod · 0.45
AddrMethod · 0.45
ErrorMethod · 0.45
AcceptMethod · 0.45

Tested by 9

TestTunnelFunction · 0.76
serveTailnetHTTPFunction · 0.76
TestServer_X11Function · 0.76
TestNewServer_SignalFunction · 0.76