Add deadline to the listeners
Call this deadline to the listener will timeout and we will get to so if the server should shutdown.
This commit is contained in:
parent
f3a6c86462
commit
0d300b1fce
16
server.go
16
server.go
|
@ -217,13 +217,13 @@ type Server struct {
|
||||||
// Default buffer size to use to read incoming UDP messages. If not set
|
// Default buffer size to use to read incoming UDP messages. If not set
|
||||||
// it defaults to MinMsgSize (512 B).
|
// it defaults to MinMsgSize (512 B).
|
||||||
UDPSize int
|
UDPSize int
|
||||||
// The net.Conn.SetReadTimeout value for new connections, defaults to 2 seconds.
|
// The net.Conn.SetReadTimeout value for new connections, defaults to 2 * time.Second.
|
||||||
ReadTimeout time.Duration
|
ReadTimeout time.Duration
|
||||||
// The net.Conn.SetWriteTimeout value for new connections, defaults to 2 seconds.
|
// The net.Conn.SetWriteTimeout value for new connections, defaults to 2 * time.Second.
|
||||||
WriteTimeout time.Duration
|
WriteTimeout time.Duration
|
||||||
// TCP idle timeout for multiple queries, if nil, defaults to 8 * time.Second (RFC 5966).
|
// TCP idle timeout for multiple queries, if nil, defaults to 8 * time.Second (RFC 5966).
|
||||||
IdleTimeout func() time.Duration
|
IdleTimeout func() time.Duration
|
||||||
// Listener deadline timeout, defaults to 2 seconds.
|
// Listener deadline timeout, defaults to 1 * time.Second.
|
||||||
Deadline time.Duration
|
Deadline time.Duration
|
||||||
// Secret(s) for Tsig map[<zonename>]<base64 secret>.
|
// Secret(s) for Tsig map[<zonename>]<base64 secret>.
|
||||||
TsigSecret map[string]string
|
TsigSecret map[string]string
|
||||||
|
@ -321,7 +321,12 @@ func (srv *Server) serveTCP(l *net.TCPListener) error {
|
||||||
if srv.ReadTimeout != 0 {
|
if srv.ReadTimeout != 0 {
|
||||||
rtimeout = srv.ReadTimeout
|
rtimeout = srv.ReadTimeout
|
||||||
}
|
}
|
||||||
|
deadline := 1 * time.Second
|
||||||
|
if srv.Deadline != 0 {
|
||||||
|
deadline = srv.Deadline
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
|
l.SetDeadline(time.Now().Add(deadline))
|
||||||
rw, e := l.AcceptTCP()
|
rw, e := l.AcceptTCP()
|
||||||
select {
|
select {
|
||||||
case <-srv.stopTCP:
|
case <-srv.stopTCP:
|
||||||
|
@ -355,7 +360,12 @@ func (srv *Server) serveUDP(l *net.UDPConn) error {
|
||||||
if srv.ReadTimeout != 0 {
|
if srv.ReadTimeout != 0 {
|
||||||
rtimeout = srv.ReadTimeout
|
rtimeout = srv.ReadTimeout
|
||||||
}
|
}
|
||||||
|
deadline := 1 * time.Second
|
||||||
|
if srv.Deadline != 0 {
|
||||||
|
deadline = srv.Deadline
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
|
l.SetDeadline(time.Now().Add(deadline))
|
||||||
m, s, e := srv.readUDP(l, rtimeout)
|
m, s, e := srv.readUDP(l, rtimeout)
|
||||||
select {
|
select {
|
||||||
case <-srv.stopUDP:
|
case <-srv.stopUDP:
|
||||||
|
|
Loading…
Reference in New Issue