dns: query in udp when client requests in udp and no forwarder specified

This commit is contained in:
nadoo committed 2018-08-02 00:11:22 +08:00
1 parent 8d20331096
commit 9acaff5b4a
4 files changed
+118 -72

No files matched your search

+10 -12
View File
@@ -42,20 +42,18 @@ func (c *Cache) Len() int {
return len(c.m)
}
// Put an item into cache, invalid after ttl seconds, never invalid if ttl=0
// Put an item into cache, invalid after ttl seconds
func (c *Cache) Put(k string, v []byte, ttl int) {
if len(v) == 0 {
return
if len(v) != 0 {
c.l.Lock()
it, ok := c.m[k]
if !ok {
it = &item{value: v}
c.m[k] = it
}
it.expire = time.Now().Add(time.Duration(ttl) * time.Second)
c.l.Unlock()
}
c.l.Lock()
it, ok := c.m[k]
if !ok {
it = &item{value: v}
c.m[k] = it
}
it.expire = time.Now().Add(time.Duration(ttl) * time.Second)
c.l.Unlock()
}
// Get an item from cache