From f8a6b1bb0a5a0c38a7a98f565c276a3517f0db59 Mon Sep 17 00:00:00 2001 From: dingjun Date: Thu, 1 Sep 2022 15:06:59 +0800 Subject: [PATCH] add err check --- server_https.go | 4 +++- server_tcp.go | 5 ++++- server_udp.go | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server_https.go b/server_https.go index 6c6d6d3..4c3cf36 100644 --- a/server_https.go +++ b/server_https.go @@ -52,7 +52,9 @@ func (srv *server) handleHTTPReq(w http.ResponseWriter, r *http.Request) { } w.Header().Set("content-type", dnsMsgType) d, _ := m.Pack() - w.Write(d) + if _, err := w.Write(d); err != nil { + log.Errorln(err) + } } func (srv *server) ServeHTTP(w http.ResponseWriter, r *http.Request) { diff --git a/server_tcp.go b/server_tcp.go index 3903d14..9530cad 100644 --- a/server_tcp.go +++ b/server_tcp.go @@ -27,6 +27,9 @@ func (srv *server) handleTCP(c net.Conn) { for _, a := range m.Answer { log.Debugln("result", a.String()) } - conn.WriteMsg(m) + if err := conn.WriteMsg(m); err != nil { + log.Errorln(err) + break + } } } diff --git a/server_udp.go b/server_udp.go index 7531d16..6953463 100644 --- a/server_udp.go +++ b/server_udp.go @@ -24,5 +24,7 @@ func (srv *server) handleUDP(buf []byte, addr net.Addr, conn *net.UDPConn) { log.Debugln("result", a.String()) } d, _ := m.Pack() - conn.WriteTo(d, addr) + if _, err := conn.WriteTo(d, addr); err != nil { + log.Errorln(err) + } }