Skip to content

Commit

Permalink
Make MaxTCPQueries configurable (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uladzimir Trehubenka authored and miekg committed May 14, 2018
1 parent 77d95a5 commit 621df09
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"time"
)

// Maximum number of TCP queries before we close the socket.
// Default maximum number of TCP queries before we close the socket.
const maxTCPQueries = 128

// Interval for stop worker if no load
Expand Down Expand Up @@ -303,6 +303,8 @@ type Server struct {
DecorateReader DecorateReader
// DecorateWriter is optional, allows customization of the process that writes raw DNS messages.
DecorateWriter DecorateWriter
// Maximum number of TCP queries before we close the socket. Default is maxTCPQueries (unlimited if -1).
MaxTCPQueries int

// UDP packet or TCP connection queue
queue chan *response
Expand Down Expand Up @@ -593,8 +595,12 @@ func (srv *Server) serve(w *response) {

timeout := srv.getReadTimeout()

// TODO(miek): make maxTCPQueries configurable?
for q := 0; q < maxTCPQueries; q++ {
limit := srv.MaxTCPQueries
if limit == 0 {
limit = maxTCPQueries
}

for q := 0; q < limit || limit == -1; q++ {
var err error
w.msg, err = reader.ReadTCP(w.tcp, timeout)
if err != nil {
Expand Down

0 comments on commit 621df09

Please sign in to comment.