blob: 033d0d7b1b3021102f702b67f4c8eb52d85a4e94 [file] [log] [blame]
Don Newton379ae252019-04-01 12:17:06 -04001// Copyright (C) MongoDB, Inc. 2017-present.
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may
4// not use this file except in compliance with the License. You may obtain
5// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
7package connection
8
9import "context"
10
11// Server is used to handle incoming Connections. It handles the boilerplate of accepting a
12// Connection and cleaning it up after running a Handler. This also makes it easier to build
13// higher level processors, like proxies, by handling the life cycle of the underlying
14// connection.
15//
16// TODO(GODRIVER-269): Implement this.
17type Server struct {
18 Addr Addr
19 Handler Handler
20}
21
22// ListenAndServe listens on the network address srv.Addr and calls Serve to
23// handle requests on incoming connections. If srv.Addr is blank, "localhost:27017"
24// is used.
25func (*Server) ListenAndServe() error { return nil }
26
27// Serve accepts incoming connections on the Listener l, creating a new service
28// goroutine for each. The service goroutines call srv.Handler and do not processing
29// beforehand. When srv.Handler returns, the connection is closed.
30func (*Server) Serve(Listener) error { return nil }
31
32// Shutdown gracefully shuts down the server by closing the active listeners. Shutdown
33// does not handle or wait for all open connections to close and return before returning.
34func (*Server) Shutdown(context.Context) error { return nil }
35
36// Handler handles an individual Connection. Returning signals that the Connection
37// is no longer needed and can be closed.
38type Handler interface {
39 HandleConnection(Connection)
40}