Github user jacksontj commented on a diff in the pull request: https://github.com/apache/trafficserver/pull/653#discussion_r66985114 --- Diff: iocore/hostdb/I_HostDBProcessor.h --- @@ -139,10 +141,62 @@ struct SRVInfo { unsigned int key; }; -struct HostDBInfo { +struct HostDBInfo : public RefCountObj { /** Internal IP address data. This is at least large enough to hold an IPv6 address. */ + + int iobuffer_index; + static HostDBInfo * + alloc(int size = 0) + { + size += sizeof(HostDBInfo); + int iobuffer_index = iobuffer_size_to_index(size); + ink_release_assert(iobuffer_index >= 0); + void *ptr = ioBufAllocator[iobuffer_index].alloc_void(); + memset(ptr, 0, size); + HostDBInfo *ret = new (ptr) HostDBInfo(); + ret->iobuffer_index = iobuffer_index; + return ret; + } + + void + free() + { + ioBufAllocator[iobuffer_index].free_void((void *)(this)); + } + + // return a version number-- so we can manage compatibility with the marshal/unmarshal + static VersionNumber + version() + { + return VersionNumber(1, 0); + } + + static HostDBInfo * + unmarshall(char *buf, unsigned int size) + { + if (size < sizeof(HostDBInfo)) { + return NULL; + } + HostDBInfo *ret = HostDBInfo::alloc(size - sizeof(HostDBInfo)); + int buf_index = ret->iobuffer_index; + memcpy((void *)ret, buf, size); + // Reset the refcount back to 0, this is a bit ugly-- but I'm not sure we want to expose a method + // to mess with the refcount, since this is a fairly unique use case + ret = new (ret) HostDBInfo(); --- End diff -- This one I actually brought up in our email convo. Right now alloc takes the size *over* the struct it is allocating-- so its a bit confusing. I think I'm going to change it to just take a size and then just error if size is not large enough (to avoid this confusion).
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---