trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jplev...@apache.org
Subject svn commit: r1095127 - in /trafficserver/traffic/trunk: iocore/dns/DNS.cc iocore/dns/I_DNSProcessor.h iocore/dns/P_DNSProcessor.h lib/ts/Ptr.h
Date Tue, 19 Apr 2011 16:22:00 GMT
Author: jplevyak
Date: Tue Apr 19 16:22:00 2011
New Revision: 1095127

URL: http://svn.apache.org/viewvc?rev=1095127&view=rev
Log:
TS-716: fix for DNS crash: bad memory management of HostEnt structures.   It is not clear
that this
fixes the bug entirely.  Some of the stack traces are consistent with this bug, but some are
not.

Modified:
    trafficserver/traffic/trunk/iocore/dns/DNS.cc
    trafficserver/traffic/trunk/iocore/dns/I_DNSProcessor.h
    trafficserver/traffic/trunk/iocore/dns/P_DNSProcessor.h
    trafficserver/traffic/trunk/lib/ts/Ptr.h

Modified: trafficserver/traffic/trunk/iocore/dns/DNS.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/dns/DNS.cc?rev=1095127&r1=1095126&r2=1095127&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/dns/DNS.cc (original)
+++ trafficserver/traffic/trunk/iocore/dns/DNS.cc Tue Apr 19 16:22:00 2011
@@ -63,12 +63,12 @@ ClassAllocator<HostEnt> dnsBufAllocator(
 //
 // Function Prototypes
 //
-static bool dns_process(DNSHandler * h, HostEnt * ent, int len);
-static DNSEntry *get_dns(DNSHandler * h, uint16_t id);
+static bool dns_process(DNSHandler *h, HostEnt *ent, int len);
+static DNSEntry *get_dns(DNSHandler *h, uint16_t id);
 // returns true when e is done
-static void dns_result(DNSHandler * h, DNSEntry * e, HostEnt * ent, bool retry);
-static void write_dns(DNSHandler * h);
-static bool write_dns_event(DNSHandler * h, DNSEntry * e);
+static void dns_result(DNSHandler *h, DNSEntry *e, HostEnt *ent, bool retry);
+static void write_dns(DNSHandler *h);
+static bool write_dns_event(DNSHandler *h, DNSEntry *e);
 
 // "reliable" name to try. need to build up first.
 static int try_servers = 0;
@@ -78,11 +78,9 @@ char try_server_names[DEFAULT_NUM_TRY_SE
 
 
 static inline char *
-strnchr(char *s, char c, int len)
-{
+strnchr(char *s, char c, int len) {
   while (*s && *s != c && len)
     ++s, --len;
-
   return *s == c ? s : (char *) NULL;
 }
 
@@ -94,20 +92,17 @@ ink_get16(const uint8_t *src) {
   return dst;
 }
 
+void HostEnt::free() {
+  dnsBufAllocator.free(this);
+}
+
 //
 //  Public functions
 //
 //  See documentation is header files and Memos
 //
-inline void
-DNSProcessor::free_hostent(HostEnt * ent)
-{
-  dnsBufAllocator.free(ent);
-}
-
 int
-DNSProcessor::start(int)
-{
+DNSProcessor::start(int) {
   //
   // Read configuration
   //
@@ -236,7 +231,7 @@ DNSProcessor::dns_init()
 
 */
 inline int
-ink_dn_expand(const u_char * msg, const u_char * eom, const u_char * comp_dn, u_char * exp_dn,
int length)
+ink_dn_expand(const u_char *msg, const u_char *eom, const u_char *comp_dn, u_char *exp_dn,
int length)
 {
   return::dn_expand((unsigned char *) msg, (unsigned char *) eom, (unsigned char *) comp_dn,
(char *) exp_dn, length);
 }
@@ -249,12 +244,11 @@ DNSProcessor::DNSProcessor()
 
 void
 DNSEntry::init(const char *x, int len, int qtype_arg,
-               Continuation * acont, HostEnt ** wait, DNSHandler * adnsH, int dns_lookup_timeout)
+               Continuation *acont, DNSHandler *adnsH, int dns_lookup_timeout)
 {
   qtype = qtype_arg;
   submit_time = ink_get_hrtime();
   action = acont;
-  sem_ent = wait;
   submit_thread = acont->mutex->thread_holding;
 
 #ifdef SPLIT_DNS
@@ -314,19 +308,6 @@ DNSEntry::init(const char *x, int len, i
     ink_strncpy(p, "in-addr.arpa", MAXDNAME - (p - qname + 1));
   }
 
-  if (sem_ent) {
-#if defined(darwin)
-    static int qnum = 0;
-    char sname[NAME_MAX];
-
-    qnum++;
-    snprintf(sname,NAME_MAX,"%s%d","DNSEntry",qnum);
-    ink_sem_unlink(sname); // FIXME: remove, semaphore should be properly deleted after usage
-    sem = ink_sem_open(sname, O_CREAT | O_EXCL, 0777, 0);
-#else /* !darwin */
-    ink_sem_init(&sem, 0);
-#endif /* !darwin */
-  }
   SET_HANDLER((DNSEntryHandler) & DNSEntry::mainEvent);
 }
 
@@ -378,7 +359,7 @@ DNSHandler::open_con(unsigned int aip, i
 
 */
 int
-DNSHandler::startEvent(int event, Event * e)
+DNSHandler::startEvent(int event, Event *e)
 {
   NOWARN_UNUSED(event);
   //
@@ -437,7 +418,7 @@ DNSHandler::startEvent(int event, Event 
   hander to a new nameserver.
 */
 int
-DNSHandler::startEvent_sdns(int event, Event * e)
+DNSHandler::startEvent_sdns(int event, Event *e)
 {
   NOWARN_UNUSED(event);
   Debug("dns", "DNSHandler::startEvent_sdns: on thread %d\n", e->ethread->id);
@@ -537,7 +518,7 @@ DNSHandler::try_primary_named(bool reope
 void
 DNSHandler::switch_named(int ndx)
 {
-  for (DNSEntry * e = entries.head; e; e = (DNSEntry *) e->link.next) {
+  for (DNSEntry *e = entries.head; e; e = (DNSEntry *) e->link.next) {
     e->written_flag = 0;
     if (e->retries < dns_retries)
       ++(e->retries);           // give them another chance
@@ -611,7 +592,7 @@ DNSHandler::rr_failure(int ndx)
     Warning("connection to all DNS servers lost, retrying");
     // actual retries will be done in retry_named called from mainEvent
     // mark any outstanding requests as not sent for later retry
-    for (DNSEntry * e = entries.head; e; e = (DNSEntry *) e->link.next) {
+    for (DNSEntry *e = entries.head; e; e = (DNSEntry *) e->link.next) {
       e->written_flag = 0;
       if (e->retries < dns_retries)
         ++(e->retries);         // give them another chance
@@ -620,7 +601,7 @@ DNSHandler::rr_failure(int ndx)
     }
   } else {
     // move outstanding requests that were sent to this nameserver to another
-    for (DNSEntry * e = entries.head; e; e = (DNSEntry *) e->link.next) {
+    for (DNSEntry *e = entries.head; e; e = (DNSEntry *) e->link.next) {
       if (e->which_ns == ndx) {
         e->written_flag = 0;
         if (e->retries < dns_retries)
@@ -647,7 +628,7 @@ good_rcode(char *buf)
 
 
 void
-DNSHandler::recv_dns(int event, Event * e)
+DNSHandler::recv_dns(int event, Event *e)
 {
   NOWARN_UNUSED(event);
   NOWARN_UNUSED(e);
@@ -660,8 +641,8 @@ DNSHandler::recv_dns(int event, Event * 
 
       if (!hostent_cache)
         hostent_cache = dnsBufAllocator.alloc();
-
       HostEnt *buf = hostent_cache;
+
       int res = socketManager.recvfrom(dnsc->fd, buf->buf, MAX_DNS_PACKET_LEN, 0, (struct
sockaddr *) &sa_from, &sa_length);
 
       if (res == -EAGAIN)
@@ -681,7 +662,6 @@ DNSHandler::recv_dns(int event, Event * 
         continue;
       }
       hostent_cache = 0;
-      buf->ref_count = 1;
       buf->packet_size = res;
       Debug("dns", "received packet size = %d", res);
       if (dns_ns_rr) {
@@ -706,18 +686,19 @@ DNSHandler::recv_dns(int event, Event * 
           }
         }
       }
-
+      Ptr<HostEnt> protect_hostent = buf;
       if (dns_process(this, buf, res)) {
         if (dnsc->num == name_server)
           received_one(name_server);
       }
+      hostent_cache = protect_hostent.to_ptr();
     }
   }
 }
 
 /** Main event for the DNSHandler. Attempt to read from and write to named. */
 int
-DNSHandler::mainEvent(int event, Event * e)
+DNSHandler::mainEvent(int event, Event *e)
 {
   recv_dns(event, e);
   if (dns_ns_rr) {
@@ -765,9 +746,9 @@ DNSHandler::mainEvent(int event, Event *
 
 /** Find a DNSEntry by id. */
 inline static DNSEntry *
-get_dns(DNSHandler * h, uint16_t id)
+get_dns(DNSHandler *h, uint16_t id)
 {
-  for (DNSEntry * e = h->entries.head; e; e = (DNSEntry *) e->link.next) {
+  for (DNSEntry *e = h->entries.head; e; e = (DNSEntry *) e->link.next) {
     if (e->once_written_flag)
       for (int j = 0; j < MAX_DNS_RETRIES; j++)
         if (e->id[j] == id)
@@ -781,9 +762,9 @@ get_dns(DNSHandler * h, uint16_t id)
 
 /** Find a DNSEntry by query name and type. */
 inline static DNSEntry *
-get_entry(DNSHandler * h, char *qname, int qtype)
+get_entry(DNSHandler *h, char *qname, int qtype)
 {
-  for (DNSEntry * e = h->entries.head; e; e = (DNSEntry *) e->link.next) {
+  for (DNSEntry *e = h->entries.head; e; e = (DNSEntry *) e->link.next) {
     if (e->qtype == qtype) {
       if (qtype == T_A) {
         if (!strcmp(qname, e->qname))
@@ -797,7 +778,7 @@ get_entry(DNSHandler * h, char *qname, i
 
 /** Write up to dns_max_dns_in_flight entries. */
 static void
-write_dns(DNSHandler * h)
+write_dns(DNSHandler *h)
 {
   ProxyMutex *mutex = h->mutex;
   DNS_INCREMENT_DYN_STAT(dns_total_lookups_stat);
@@ -871,7 +852,7 @@ DNSHandler::get_query_id()
 
 */
 static bool
-write_dns_event(DNSHandler * h, DNSEntry * e)
+write_dns_event(DNSHandler *h, DNSEntry *e)
 {
   ProxyMutex *mutex = h->mutex;
   char buffer[MAX_DNS_PACKET_LEN];
@@ -929,7 +910,7 @@ write_dns_event(DNSHandler * h, DNSEntry
 
 
 int
-DNSEntry::delayEvent(int event, Event * e)
+DNSEntry::delayEvent(int event, Event *e)
 {
   (void) event;
   if (dnsProcessor.handler) {
@@ -942,7 +923,7 @@ DNSEntry::delayEvent(int event, Event * 
 
 /** Handle timeout events. */
 int
-DNSEntry::mainEvent(int event, Event * e)
+DNSEntry::mainEvent(int event, Event *e)
 {
   switch (event) {
   default:
@@ -996,34 +977,21 @@ DNSEntry::mainEvent(int event, Event * e
   }
 }
 
-
 Action *
-DNSProcessor::getby(const char *x, int len, int type,
-                    Continuation * cont, HostEnt ** wait, DNSHandler * adnsH, int timeout)
-{
+DNSProcessor::getby(const char *x, int len, int type, Continuation *cont, DNSHandler *adnsH,
int timeout) {
   Debug("dns", "received query %s type = %d, timeout = %d", x, type, timeout);
   if (type == T_SRV) {
     Debug("dns_srv", "DNSProcessor::getby attempting an SRV lookup for %s, timeout = %d",
x, timeout);
   }
-
   DNSEntry *e = dnsEntryAllocator.alloc();
-
   e->retries = dns_retries;
-  e->init(x, len, type, cont, wait, adnsH, timeout);
+  e->init(x, len, type, cont, adnsH, timeout);
   MUTEX_TRY_LOCK(lock, e->mutex, thread);
-  if (!lock) {
+  if (!lock)
     thread->schedule_imm(e);
-  } else {
+  else
     e->handleEvent(EVENT_IMMEDIATE, 0);
-  }
-  if (wait) {
-#if defined(darwin)
-    ink_sem_wait(e->sem);
-#else
-    ink_sem_wait(&e->sem);
-#endif
-  }
-  return wait ? ACTION_RESULT_DONE : &e->action;
+  return &e->action;
 }
 
 /**
@@ -1031,8 +999,7 @@ DNSProcessor::getby(const char *x, int l
   is a retry-able and we have retries left.
 */
 static void
-dns_result(DNSHandler * h, DNSEntry * e, HostEnt * ent, bool retry)
-{
+dns_result(DNSHandler *h, DNSEntry *e, HostEnt *ent, bool retry) {
   ProxyMutex *mutex = h->mutex;
   bool cancelled = (e->action.cancelled ? true : false);
 
@@ -1120,15 +1087,20 @@ dns_result(DNSHandler * h, DNSEntry * e,
   }
 
   DNSEntry *dup = NULL;
-
   while ((dup = e->dups.dequeue())) {
-    if (dup->post(h, ent, false)) {
+    if (dup->post(h, ent)) {
       e->dups.enqueue(dup);
       goto Lretry;
     }
   }
-  if (!e->post(h, ent, true))
+  if (!e->post(h, ent)) {
+    for (int i = 0; i < MAX_DNS_RETRIES; i++) {
+      if (e->id[i] < 0)
+        break;
+      h->release_query_id(e->id[i]);      
+    }
     return;
+  }
 Lretry:
   e->result_ent = ent;
   e->retries = 0;
@@ -1138,50 +1110,30 @@ Lretry:
 }
 
 int
-DNSEntry::post(DNSHandler * h, HostEnt * ent, bool freeable)
+DNSEntry::post(DNSHandler *h, HostEnt *ent)
 {
-  NOWARN_UNUSED(freeable);
   if (timeout) {
     timeout->cancel(this);
     timeout = NULL;
   }
-  if (sem_ent) {
-    // If this call was synchronous, post to the semaphore
-    *sem_ent = ent;
-#if defined(darwin)
-    ink_sem_post(sem);
-#else
-    ink_sem_post(&sem);
-#endif
+  result_ent = ent;
+  if (h->mutex->thread_holding == submit_thread) {
+    MUTEX_TRY_LOCK(lock, action.mutex, h->mutex->thread_holding);
+    if (!lock) {
+      Debug("dns", "failed lock for result %s", qname);
+      return 1;
+    }
+    postEvent(0, 0);
   } else {
-    result_ent = ent;
-    if (h->mutex->thread_holding == submit_thread) {
-      MUTEX_TRY_LOCK(lock, action.mutex, h->mutex->thread_holding);
-      if (!lock) {
-        Debug("dns", "failed lock for result %s", qname);
-        return 1;
-      }
-      postEvent(0, 0);
-    } else {
-      mutex = action.mutex;
-      SET_HANDLER(&DNSEntry::postEvent);
-      submit_thread->schedule_imm_signal(this);
-    }
-    return 0;
-  }
-  for (int i = 0; i < MAX_DNS_RETRIES; i++) {
-    if (id[i] < 0)
-      break;
-    h->release_query_id(id[i]);      
+    mutex = action.mutex;
+    SET_HANDLER(&DNSEntry::postEvent);
+    submit_thread->schedule_imm_signal(this);
   }
-  action.mutex = NULL;
-  mutex = NULL;
-  dnsEntryAllocator.free(this);
   return 0;
 }
 
 int
-DNSEntry::postEvent(int event, Event * e)
+DNSEntry::postEvent(int event, Event *e)
 {
   NOWARN_UNUSED(event);
   NOWARN_UNUSED(e);
@@ -1189,15 +1141,7 @@ DNSEntry::postEvent(int event, Event * e
     Debug("dns", "called back continuation for %s", qname);
     action.continuation->handleEvent(DNS_EVENT_LOOKUP, result_ent);
   }
-  if (result_ent)
-    if (ink_atomic_increment(&result_ent->ref_count, -1) == 1)
-      dnsProcessor.free_hostent(result_ent);
-
-  for (int i = 0; i < MAX_DNS_RETRIES; i++) {
-    if (id[i] < 0)
-      break;
-    dnsH->release_query_id(id[i]);      
-  }
+  result_ent = NULL;
   action.mutex = NULL;
   mutex = NULL;
   dnsEntryAllocator.free(this);
@@ -1206,7 +1150,7 @@ DNSEntry::postEvent(int event, Event * e
 
 /** Decode the reply from "named". */
 static bool
-dns_process(DNSHandler * handler, HostEnt * buf, int len)
+dns_process(DNSHandler *handler, HostEnt *buf, int len)
 {
   ProxyMutex *mutex = handler->mutex;
   HEADER *h = (HEADER *) (buf->buf);
@@ -1220,10 +1164,6 @@ dns_process(DNSHandler * handler, HostEn
   //
   if (!e || !e->written_flag) {
     Debug("dns", "unknown DNS id = %u", (uint16_t) ntohs(h->id));
-    if (!handler->hostent_cache)
-      handler->hostent_cache = buf;
-    else
-      dnsBufAllocator.free(buf);
     return false;               // cannot count this as a success
   }
   //
@@ -1515,10 +1455,6 @@ dns_process(DNSHandler * handler, HostEn
   }
 Lerror:;
   DNS_INCREMENT_DYN_STAT(dns_lookup_fail_stat);
-  if (!handler->hostent_cache)
-    handler->hostent_cache = buf;
-  else
-    dnsBufAllocator.free(buf);
   dns_result(handler, e, NULL, retry);
   return server_ok;
 }
@@ -1598,7 +1534,7 @@ struct DNSRegressionContinuation: public
   int i;
   RegressionTest *test;
 
-  int mainEvent(int event, HostEnt * he)
+  int mainEvent(int event, HostEnt *he)
   {
     (void) event;
     if (event == DNS_EVENT_LOOKUP) {
@@ -1624,7 +1560,7 @@ struct DNSRegressionContinuation: public
     }
   }
 
-  DNSRegressionContinuation(int ahosts, int atofind, const char **ahostnames, RegressionTest
* t, int atype, int *astatus)
+  DNSRegressionContinuation(int ahosts, int atofind, const char **ahostnames, RegressionTest
*t, int atype, int *astatus)
    :  Continuation(new_ProxyMutex()), hosts(ahosts), hostnames(ahostnames), type(atype),
       status(astatus), found(0), tofind(atofind), i(0), test(t) {
     SET_HANDLER((DNSRegContHandler) & DNSRegressionContinuation::mainEvent);
@@ -1638,7 +1574,7 @@ static const char *dns_test_hosts[] = {
   "www.coke.com"
 };
 
-REGRESSION_TEST(DNS) (RegressionTest * t, int atype, int *pstatus) {
+REGRESSION_TEST(DNS) (RegressionTest *t, int atype, int *pstatus) {
   eventProcessor.schedule_in(NEW(new DNSRegressionContinuation(4, 4, dns_test_hosts, t, atype,
pstatus)),
                              HRTIME_SECONDS(1));
 }

Modified: trafficserver/traffic/trunk/iocore/dns/I_DNSProcessor.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/dns/I_DNSProcessor.h?rev=1095127&r1=1095126&r2=1095127&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/dns/I_DNSProcessor.h (original)
+++ trafficserver/traffic/trunk/iocore/dns/I_DNSProcessor.h Tue Apr 19 16:22:00 2011
@@ -40,11 +40,9 @@
   one will exist per call until the user deletes them.
 
 */
-struct HostEnt
-{
+struct HostEnt : RefCountObj {
   struct hostent ent;
   uint32_t ttl;
-  int ref_count;
   int packet_size;
   char buf[MAX_DNS_PACKET_LEN];
   u_char *host_aliases[DNS_MAX_ALIASES];
@@ -53,9 +51,11 @@ struct HostEnt
 
   SRVHosts srv_hosts;
 
-  HostEnt()
-  {
-    memset(this, 0, sizeof(*this));
+  virtual void free();
+
+  HostEnt() { 
+    size_t base = sizeof(force_VFPT_to_top);  // preserve VFPT
+    memset(((char*)this) + base, 0, sizeof(*this) - base); 
   }
 };
 
@@ -65,30 +65,20 @@ struct DNSHandler;
 
 struct DNSProcessor: public Processor
 {
-  //
   // Public Interface
   //
 
-  // Non-blocking DNS lookup
-  //   calls: cont->handleEvent( DNS_EVENT_LOOKUP, HostEnt * ent) on success
+  // DNS lookup
+  //   calls: cont->handleEvent( DNS_EVENT_LOOKUP, HostEnt *ent) on success
   //          cont->handleEvent( DNS_EVENT_LOOKUP, NULL) on failure
-  // NOTE: the HostEnt * block is freed when the function returns
+  // NOTE: the HostEnt *block is freed when the function returns
   //
 
-  Action *gethostbyname(Continuation * cont, const char *name, DNSHandler * adnsH = 0, int
timeout = 0);
-  Action *getSRVbyname(Continuation * cont, const char *name, DNSHandler * adnsH = 0, int
timeout = 0);
-  Action *gethostbyname(Continuation * cont, const char *name, int len, int timeout = 0);
-  Action *gethostbyaddr(Continuation * cont, unsigned int ip, int timeout = 0);
+  Action *gethostbyname(Continuation *cont, const char *name, DNSHandler *adnsH = 0, int
timeout = 0);
+  Action *getSRVbyname(Continuation *cont, const char *name, DNSHandler *adnsH = 0, int timeout
= 0);
+  Action *gethostbyname(Continuation *cont, const char *name, int len, int timeout = 0);
+  Action *gethostbyaddr(Continuation *cont, unsigned int ip, int timeout = 0);
 
-  // Blocking DNS lookup, user must free the return HostEnt *
-  // NOTE: this HostEnt is big, please free these ASAP
-  //
-  HostEnt *gethostbyname(const char *name);
-  HostEnt *gethostbyaddr(unsigned int addr);
-  HostEnt *getSRVbyname(const char *name);
-
-  /** Free the returned HostEnt (only for Blocking versions). */
-  void free_hostent(HostEnt * ent);
 
   // Processor API
   //
@@ -102,14 +92,12 @@ struct DNSProcessor: public Processor
 
   DNSProcessor();
 
-  //
   // private:
   //
   EThread *thread;
   DNSHandler *handler;
   __ink_res_state l_res;
-  Action *getby(const char *x, int len, int type, Continuation * cont,
-                HostEnt ** wait, DNSHandler * adnsH = NULL, int timeout = 0);
+  Action *getby(const char *x, int len, int type, Continuation *cont, DNSHandler *adnsH =
NULL, int timeout = 0);
   void dns_init();
 };
 
@@ -123,59 +111,28 @@ extern DNSProcessor dnsProcessor;
 // Inline Functions
 //
 
-inline HostEnt *
-DNSProcessor::getSRVbyname(const char *name)
-{
-  HostEnt *ent = NULL;
-
-  getby(name, 0, T_SRV, NULL, &ent);
-  return ent;
-}
-
-
 inline Action *
-DNSProcessor::getSRVbyname(Continuation * cont, const char *name, DNSHandler * adnsH, int
timeout)
+DNSProcessor::getSRVbyname(Continuation *cont, const char *name, DNSHandler *adnsH, int timeout)
 {
-  return getby(name, 0, T_SRV, cont, 0, adnsH, timeout);
+  return getby(name, 0, T_SRV, cont, adnsH, timeout);
 }
 
-
 inline Action *
-DNSProcessor::gethostbyname(Continuation * cont, const char *name, DNSHandler * adnsH, int
timeout)
+DNSProcessor::gethostbyname(Continuation *cont, const char *name, DNSHandler *adnsH, int
timeout)
 {
-  return getby(name, 0, T_A, cont, 0, adnsH, timeout);
+  return getby(name, 0, T_A, cont, adnsH, timeout);
 }
 
-
 inline Action *
-DNSProcessor::gethostbyname(Continuation * cont, const char *name, int len, int timeout)
+DNSProcessor::gethostbyname(Continuation *cont, const char *name, int len, int timeout)
 {
-  return getby(name, len, T_A, cont, 0, NULL, timeout);
+  return getby(name, len, T_A, cont, NULL, timeout);
 }
 
-
 inline Action *
-DNSProcessor::gethostbyaddr(Continuation * cont, unsigned int addr, int timeout)
-{
-  return getby((char *) &addr, sizeof(addr), T_PTR, cont, 0, NULL, timeout);
-}
-
-
-inline HostEnt *
-DNSProcessor::gethostbyname(const char *name)
-{
-  HostEnt *ent = NULL;
-  getby(name, 0, T_A, NULL, &ent);
-  return ent;
-}
-
-
-inline HostEnt *
-DNSProcessor::gethostbyaddr(unsigned int addr)
+DNSProcessor::gethostbyaddr(Continuation *cont, unsigned int addr, int timeout)
 {
-  HostEnt *ent = NULL;
-  getby((char *) &addr, sizeof(addr), T_PTR, NULL, &ent);
-  return ent;
+  return getby((char *) &addr, sizeof(addr), T_PTR, cont, NULL, timeout);
 }
 
 void ink_dns_init(ModuleVersion version);

Modified: trafficserver/traffic/trunk/iocore/dns/P_DNSProcessor.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/dns/P_DNSProcessor.h?rev=1095127&r1=1095126&r2=1095127&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/dns/P_DNSProcessor.h (original)
+++ trafficserver/traffic/trunk/iocore/dns/P_DNSProcessor.h Tue Apr 19 16:22:00 2011
@@ -157,46 +157,32 @@ struct DNSEntry: public Continuation
   int qname_len;
   char **domains;
   EThread *submit_thread;
-
   Action action;
-
   Event *timeout;
-  HostEnt *result_ent;
-
-  HostEnt **sem_ent;
-#if defined(darwin)
-  ink_sem *sem;
-#else
-  ink_sem sem;
-#endif
+  Ptr<HostEnt> result_ent;
   DNSHandler *dnsH;
-
-
   bool written_flag;
   bool once_written_flag;
   bool last;
   LINK(DNSEntry, dup_link);
   Que(DNSEntry, dup_link) dups;
 
-  int mainEvent(int event, Event * e);
-  int delayEvent(int event, Event * e);
-  int post(DNSHandler * h, HostEnt * ent, bool freeable);
-  int postEvent(int event, Event * e);
-
-  void init(const char *x, int len, int qtype_arg, Continuation * acont, HostEnt ** wait,
DNSHandler * adnsH, int timeout);
+  int mainEvent(int event, Event *e);
+  int delayEvent(int event, Event *e);
+  int post(DNSHandler *h, HostEnt *ent);
+  int postEvent(int event, Event *e);
+  void init(const char *x, int len, int qtype_arg, Continuation *acont, DNSHandler *adnsH,
int timeout);
 
    DNSEntry()
      : Continuation(NULL),
        qtype(0),
        retries(DEFAULT_DNS_RETRIES),
        which_ns(NO_NAMESERVER_SELECTED), submit_time(0), send_time(0), qname_len(0), domains(0),
-       timeout(0), result_ent(0), sem_ent(0), dnsH(0), written_flag(false), once_written_flag(false),
last(false)
+       timeout(0), result_ent(0), dnsH(0), written_flag(false), once_written_flag(false),
last(false)
   {
     for (int i = 0; i < MAX_DNS_RETRIES; i++)
       id[i] = -1;
-
     memset(qname, 0, MAXDNAME);
-    memset(&sem, 0, sizeof sem);
   }
 };
 
@@ -270,10 +256,10 @@ struct DNSHandler: public Continuation
              (HRTIME_SECONDS(dns_failover_try_period + failover_soon_number[i] * FAILOVER_SOON_RETRY))));
   }
 
-  void recv_dns(int event, Event * e);
-  int startEvent(int event, Event * e);
-  int startEvent_sdns(int event, Event * e);
-  int mainEvent(int event, Event * e);
+  void recv_dns(int event, Event *e);
+  int startEvent(int event, Event *e);
+  int startEvent_sdns(int event, Event *e);
+  int mainEvent(int event, Event *e);
 
   void open_con(unsigned int aip, int aport, bool failed = false, int icon = 0);
   void failover();

Modified: trafficserver/traffic/trunk/lib/ts/Ptr.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/Ptr.h?rev=1095127&r1=1095126&r2=1095127&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/Ptr.h (original)
+++ trafficserver/traffic/trunk/lib/ts/Ptr.h Tue Apr 19 16:22:00 2011
@@ -304,6 +304,15 @@ public:
   Ptr<T> &operator =(const Ptr<T> &);
   Ptr<T> &operator =(T *);
 
+  T * to_ptr() {
+    if (m_ptr && m_ptr->m_refcount == 1) {
+      T * ptr = m_ptr;
+      m_ptr = 0;
+      ptr->m_refcount = 0;
+      return ptr;
+    }
+    return 0;
+  }
   operator  T *() const
   {
     return (m_ptr);



Mime
View raw message