forked from zenazn/goji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.go
33 lines (25 loc) · 805 Bytes
/
serve.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// +build !go1.3
package graceful
import (
"net"
"net/http"
"time"
"github.com/zenazn/goji/graceful/listener"
)
// About 200 years, also known as "forever"
const forever time.Duration = 200 * 365 * 24 * time.Hour
// Serve behaves like the method on net/http.Server with the same name.
func (srv *Server) Serve(l net.Listener) error {
// Spawn a shadow http.Server to do the actual servering. We do this
// because we need to sketch on some of the parameters you passed in,
// and it's nice to keep our sketching to ourselves.
shadow := *(*http.Server)(srv)
if shadow.ReadTimeout == 0 {
shadow.ReadTimeout = forever
}
shadow.Handler = middleware(shadow.Handler)
wrap := listener.Wrap(l, listener.Deadline)
appendListener(wrap)
err := shadow.Serve(wrap)
return peacefulError(err)
}