Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 1 | // 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 | |
| 7 | package connection |
| 8 | |
| 9 | import "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. |
| 17 | type 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. |
| 25 | func (*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. |
| 30 | func (*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. |
| 34 | func (*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. |
| 38 | type Handler interface { |
| 39 | HandleConnection(Connection) |
| 40 | } |