mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-17 19:08:25 -07:00
51 lines
982 B
Go
51 lines
982 B
Go
package dnsforward
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"os"
|
|
"path"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
func isConnClosed(err error) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
nerr, ok := err.(*net.OpError)
|
|
if !ok {
|
|
return false
|
|
}
|
|
|
|
if strings.Contains(nerr.Err.Error(), "use of closed network connection") {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// ---------------------
|
|
// debug logging helpers
|
|
// ---------------------
|
|
func _Func() string {
|
|
pc := make([]uintptr, 10) // at least 1 entry needed
|
|
runtime.Callers(2, pc)
|
|
f := runtime.FuncForPC(pc[0])
|
|
return path.Base(f.Name())
|
|
}
|
|
|
|
func trace(format string, args ...interface{}) {
|
|
pc := make([]uintptr, 10) // at least 1 entry needed
|
|
runtime.Callers(2, pc)
|
|
f := runtime.FuncForPC(pc[0])
|
|
var buf strings.Builder
|
|
buf.WriteString(fmt.Sprintf("%s(): ", path.Base(f.Name())))
|
|
text := fmt.Sprintf(format, args...)
|
|
buf.WriteString(text)
|
|
if len(text) == 0 || text[len(text)-1] != '\n' {
|
|
buf.WriteRune('\n')
|
|
}
|
|
fmt.Fprint(os.Stderr, buf.String())
|
|
}
|