MCPcopy
hub / github.com/gliderlabs/ssh / Serve

Method Serve

server.go:236–273  ·  view source on GitHub ↗

Serve accepts incoming connections on the Listener l, creating a new connection goroutine for each. The connection goroutines read requests and then calls srv.Handler to handle sessions. Serve always returns a non-nil error.

(l net.Listener)

Source from the content-addressed store, hash-verified

234//
235// Serve always returns a non-nil error.
236func (srv *Server) Serve(l net.Listener) error {
237 srv.ensureHandlers()
238 defer l.Close()
239 if err := srv.ensureHostSigner(); err != nil {
240 return err
241 }
242 if srv.Handler == nil {
243 srv.Handler = DefaultHandler
244 }
245 var tempDelay time.Duration
246
247 srv.trackListener(l, true)
248 defer srv.trackListener(l, false)
249 for {
250 conn, e := l.Accept()
251 if e != nil {
252 select {
253 case <-srv.getDoneChan():
254 return ErrServerClosed
255 default:
256 }
257 if ne, ok := e.(net.Error); ok && ne.Temporary() {
258 if tempDelay == 0 {
259 tempDelay = 5 * time.Millisecond
260 } else {
261 tempDelay *= 2
262 }
263 if max := 1 * time.Second; tempDelay > max {
264 tempDelay = max
265 }
266 time.Sleep(tempDelay)
267 continue
268 }
269 return e
270 }
271 go srv.HandleConn(conn)
272 }
273}
274
275func (srv *Server) HandleConn(newConn net.Conn) {
276 ctx, cancel := newContext(srv)

Callers 5

ListenAndServeMethod · 0.95
TestServerShutdownFunction · 0.95
TestServerCloseFunction · 0.95
ServeFunction · 0.95
SftpHandlerFunction · 0.95

Calls 6

ensureHandlersMethod · 0.95
ensureHostSignerMethod · 0.95
trackListenerMethod · 0.95
getDoneChanMethod · 0.95
HandleConnMethod · 0.95
CloseMethod · 0.45

Tested by 2

TestServerShutdownFunction · 0.76
TestServerCloseFunction · 0.76