mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
general: optimize codes
This commit is contained in:
1 parent
3c509f8b7a
commit
8f661a67a4
15 files changed
+35
-37
No files matched your search
+1
-1
@@ -221,7 +221,7 @@ func (c *Client) exchangeUDP(rc net.Conn, reqBytes []byte) ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
respBytes := make([]byte, 2+UDPMaxLen)
|
||||
respBytes := make([]byte, UDPMaxLen)
|
||||
n, err := rc.Read(respBytes[2:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ import (
|
||||
// Messages carried by UDP are restricted to 512 bytes (not counting the IP
|
||||
// or UDP headers). Longer messages are truncated and the TC bit is set in
|
||||
// the header.
|
||||
const UDPMaxLen = 510
|
||||
const UDPMaxLen = 512
|
||||
|
||||
// HeaderLen is the length of dns msg header.
|
||||
const HeaderLen = 12
|
||||
|
||||
+2
-2
@@ -60,7 +60,7 @@ func (s *Server) ListenAndServeUDP(wg *sync.WaitGroup) {
|
||||
log.F("[dns] listening UDP on %s", s.addr)
|
||||
|
||||
for {
|
||||
reqBytes := pool.GetBuffer(2 + UDPMaxLen)
|
||||
reqBytes := pool.GetBuffer(UDPMaxLen)
|
||||
|
||||
n, caddr, err := c.ReadFrom(reqBytes[2:])
|
||||
if err != nil {
|
||||
@@ -76,7 +76,7 @@ func (s *Server) ListenAndServeUDP(wg *sync.WaitGroup) {
|
||||
binary.BigEndian.PutUint16(reqBytes[:2], reqLen)
|
||||
|
||||
go func() {
|
||||
respBytes, err := s.Client.Exchange(reqBytes[:2+n], caddr.String(), false)
|
||||
respBytes, err := s.Exchange(reqBytes[:2+n], caddr.String(), false)
|
||||
defer pool.PutBuffer(reqBytes)
|
||||
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user