travis-ci
4 of 4 new or added lines in 1 file covered. (100.0%)
243 of 358 relevant lines covered (67.88%)
61.17 hits per line
1 |
package graceful
|
|
2 |
|
|
3 |
import (
|
|
4 |
"net"
|
|
5 |
"time"
|
|
6 |
) |
|
7 |
|
|
8 |
type keepAliveConn interface { |
|
9 |
SetKeepAlive(bool) error |
|
10 |
SetKeepAlivePeriod(d time.Duration) error
|
|
11 |
} |
|
12 |
|
|
13 |
// keepAliveListener sets TCP keep-alive timeouts on accepted
|
|
14 |
// connections. It's used by ListenAndServe and ListenAndServeTLS so
|
|
15 |
// dead TCP connections (e.g. closing laptop mid-download) eventually
|
|
16 |
// go away.
|
|
17 |
type keepAliveListener struct { |
|
18 |
net.Listener |
|
19 |
keepAlivePeriod time.Duration |
|
20 |
} |
|
21 |
|
|
22 |
func (ln keepAliveListener) Accept() (net.Conn, error) { |
8 only 91.2 and 91.1 ✔ |
23 |
c, err := ln.Listener.Accept() |
8 only 91.2 and 91.1 ✔ |
24 |
if err != nil { |
12 only 91.2 and 91.1 ✔ |
25 |
return nil, err |
4 only 91.2 and 91.1 ✔ |
26 |
} |
4 only 91.2 and 91.1 ✔ |
27 |
|
|
28 |
kac := c.(keepAliveConn) |
4 only 91.2 and 91.1 ✔ |
29 |
kac.SetKeepAlive(true)
|
4 only 91.2 and 91.1 ✔ |
30 |
kac.SetKeepAlivePeriod(ln.keepAlivePeriod) |
4 only 91.2 and 91.1 ✔ |
31 |
return c, nil |
4 only 91.2 and 91.1 ✔ |
32 |
} |