X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=memcache-store%2Fmemcache-store.cpp;h=722250300d8a31edb3434fad04259a9063d2a6f0;hb=b757a2480a021c4183ee6dba77d4470adbf95ef8;hp=49d238dc6f49ace3ceb4c0bf0da809931845d341;hpb=163c5e045d4375e2c9cd1d2fdb13455db5d94362;p=shibboleth%2Fsp.git diff --git a/memcache-store/memcache-store.cpp b/memcache-store/memcache-store.cpp index 49d238d..7222503 100644 --- a/memcache-store/memcache-store.cpp +++ b/memcache-store/memcache-store.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2009 Internet2 + * Copyright 2001-2010 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ /** * memcache-store.cpp * - * Storage Service using memcache (pre memcache tags) + * Storage Service using memcache (pre memcache tags). */ #if defined (_MSC_VER) || defined(__BORLANDC__) @@ -63,6 +63,7 @@ namespace xmltooling { static const XMLCh pollTimeout[] = UNICODE_LITERAL_11(p,o,l,l,T,i,m,e,o,u,t); static const XMLCh failLimit[] = UNICODE_LITERAL_9(f,a,i,l,L,i,m,i,t); static const XMLCh retryTimeout[] = UNICODE_LITERAL_12(r,e,t,r,y,T,i,m,e,o,u,t); + static const XMLCh nonBlocking[] = UNICODE_LITERAL_11(n,o,n,B,l,o,c,k,i,n,g); class mc_record { public: @@ -126,17 +127,17 @@ namespace xmltooling { ~MemcacheStorageService(); bool createString(const char* context, const char* key, const char* value, time_t expiration); - int readString(const char* context, const char* key, string* pvalue=NULL, time_t* pexpiration=NULL, int version=0); - int updateString(const char* context, const char* key, const char* value=NULL, time_t expiration=0, int version=0); + int readString(const char* context, const char* key, string* pvalue=nullptr, time_t* pexpiration=nullptr, int version=0); + int updateString(const char* context, const char* key, const char* value=nullptr, time_t expiration=0, int version=0); bool deleteString(const char* context, const char* key); bool createText(const char* context, const char* key, const char* value, time_t expiration) { return createString(context, key, value, expiration); } - int readText(const char* context, const char* key, string* pvalue=NULL, time_t* pexpiration=NULL, int version=0) { + int readText(const char* context, const char* key, string* pvalue=nullptr, time_t* pexpiration=nullptr, int version=0) { return readString(context, key, pvalue, pexpiration, version); } - int updateText(const char* context, const char* key, const char* value=NULL, time_t expiration=0, int version=0) { + int updateText(const char* context, const char* key, const char* value=nullptr, time_t expiration=0, int version=0) { return updateString(context, key, value, expiration, version); } bool deleteText(const char* context, const char* key) { @@ -472,7 +473,7 @@ bool MemcacheBase::replaceMemcache(const char *key, MemcacheBase::MemcacheBase(const DOMElement* e) : m_root(e), log(Category::getInstance("XMLTooling.MemcacheBase")), m_prefix("") { - auto_ptr_char p(e ? e->getAttributeNS(NULL,prefix) : NULL); + auto_ptr_char p(e ? e->getAttributeNS(nullptr,prefix) : nullptr); if (p.get() && *p.get()) { log.debug("INIT: GOT key prefix: %s", p.get()); m_prefix = p.get(); @@ -481,8 +482,8 @@ MemcacheBase::MemcacheBase(const DOMElement* e) : m_root(e), log(Category::getIn m_lock = Mutex::create(); log.debug("Lock created"); - memc = memcached_create(NULL); - if (memc == NULL) { + memc = memcached_create(nullptr); + if (memc == nullptr) { throw XMLToolingException("MemcacheBase::Memcache(): memcached_create() failed"); } @@ -492,16 +493,16 @@ MemcacheBase::MemcacheBase(const DOMElement* e) : m_root(e), log(Category::getIn memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, hash); log.debug("CRC hash set"); - int32_t send_timeout = 1000000; - const XMLCh* tag = e ? e->getAttributeNS(NULL, sendTimeout) : NULL; + int32_t send_timeout = 999999; + const XMLCh* tag = e ? e->getAttributeNS(nullptr, sendTimeout) : nullptr; if (tag && *tag) { send_timeout = XMLString::parseInt(tag); } log.debug("MEMCACHED_BEHAVIOR_SND_TIMEOUT will be set to %d", send_timeout); memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SND_TIMEOUT, send_timeout); - int32_t recv_timeout = 1000000; - tag = e ? e->getAttributeNS(NULL, sendTimeout) : NULL; + int32_t recv_timeout = 999999; + tag = e ? e->getAttributeNS(nullptr, sendTimeout) : nullptr; if (tag && *tag) { recv_timeout = XMLString::parseInt(tag); } @@ -509,7 +510,7 @@ MemcacheBase::MemcacheBase(const DOMElement* e) : m_root(e), log(Category::getIn memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RCV_TIMEOUT, recv_timeout); int32_t poll_timeout = 1000; - tag = e ? e->getAttributeNS(NULL, pollTimeout) : NULL; + tag = e ? e->getAttributeNS(nullptr, pollTimeout) : nullptr; if (tag && *tag) { poll_timeout = XMLString::parseInt(tag); } @@ -517,7 +518,7 @@ MemcacheBase::MemcacheBase(const DOMElement* e) : m_root(e), log(Category::getIn memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, poll_timeout); int32_t fail_limit = 5; - tag = e ? e->getAttributeNS(NULL, failLimit) : NULL; + tag = e ? e->getAttributeNS(nullptr, failLimit) : nullptr; if (tag && *tag) { fail_limit = XMLString::parseInt(tag); } @@ -525,15 +526,23 @@ MemcacheBase::MemcacheBase(const DOMElement* e) : m_root(e), log(Category::getIn memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, fail_limit); int32_t retry_timeout = 30; - tag = e ? e->getAttributeNS(NULL, retryTimeout) : NULL; + tag = e ? e->getAttributeNS(nullptr, retryTimeout) : nullptr; if (tag && *tag) { retry_timeout = XMLString::parseInt(tag); } log.debug("MEMCACHED_BEHAVIOR_RETRY_TIMEOUT will be set to %d", retry_timeout); memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, retry_timeout); + int32_t nonblock_set = 1; + tag = e ? e->getAttributeNS(nullptr, nonBlocking) : nullptr; + if (tag && *tag) { + nonblock_set = XMLString::parseInt(tag); + } + log.debug("MEMCACHED_BEHAVIOR_NO_BLOCK will be set to %d", nonblock_set); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, nonblock_set); + // Grab hosts from the configuration. - e = e ? XMLHelper::getFirstChildElement(e,Hosts) : NULL; + e = e ? XMLHelper::getFirstChildElement(e,Hosts) : nullptr; if (!e || !e->hasChildNodes()) { throw XMLToolingException("Memcache StorageService requires Hosts element in configuration."); } @@ -559,7 +568,7 @@ MemcacheBase::~MemcacheBase() { MemcacheStorageService::MemcacheStorageService(const DOMElement* e) : MemcacheBase(e), m_log(Category::getInstance("XMLTooling.MemcacheStorageService")), m_buildMap(false) { - const XMLCh* tag=e ? e->getAttributeNS(NULL,buildMap) : NULL; + const XMLCh* tag=e ? e->getAttributeNS(nullptr,buildMap) : nullptr; if (tag && *tag && XMLString::parseInt(tag) != 0) { m_buildMap = true; m_log.debug("Cache built with buildMap ON"); @@ -681,12 +690,12 @@ int MemcacheStorageService::updateString(const char* context, const char* key, c log.debug("updateString ctx: %s - key: %s", context, key); time_t final_exp = expiration; - time_t *want_expiration = NULL; + time_t *want_expiration = nullptr; if (! final_exp) { want_expiration = &final_exp; } - int read_res = readString(context, key, NULL, want_expiration, version); + int read_res = readString(context, key, nullptr, want_expiration, version); if (!read_res) { // not found @@ -749,7 +758,7 @@ void MemcacheStorageService::updateContext(const char* context, time_t expiratio // Update expiration times string value; - int read_res = readString(context, iter->c_str(), &value, NULL, 0); + int read_res = readString(context, iter->c_str(), &value, nullptr, 0); if (!read_res) { // not found