/mordor/http/connection.h
C Header | 70 lines | 50 code | 16 blank | 4 comment | 0 complexity | 8cd686b5891fcb0c722c396dd7e4d6e1 MD5 | raw file
1#ifndef __MORDOR_HTTP_CONNECTION_H__ 2#define __MORDOR_HTTP_CONNECTION_H__ 3// Copyright (c) 2009 - Mozy, Inc. 4 5#include <boost/function.hpp> 6#include <boost/shared_ptr.hpp> 7#include <boost/thread/mutex.hpp> 8 9#include "mordor/anymap.h" 10#include "http.h" 11 12namespace Mordor { 13 14class Stream; 15 16namespace HTTP { 17 18class Connection 19{ 20public: 21 boost::shared_ptr<Stream> stream() { return m_stream; } 22 23 static bool hasMessageBody(const GeneralHeaders &general, 24 const EntityHeaders &entity, 25 const std::string &method, 26 Status status, 27 bool includeEmpty = true); 28 29 /// @note Be sure to lock the cacheMutex whenever you access the cache 30 anymap &cache() { return m_cache; } 31 boost::mutex &cacheMutex() { return m_cacheMutex; } 32 33 /// lock cacheMutex and return a copy of value 34 template <class TagType> 35 typename TagType::value_type getCache(const TagType &key) 36 { 37 boost::mutex::scoped_lock lock(m_cacheMutex); 38 return m_cache[key]; 39 } 40 41 /// update cache with lock 42 template <class TagType> 43 void setCache(const TagType &key, const typename TagType::value_type& value) 44 { 45 boost::mutex::scoped_lock lock(m_cacheMutex); 46 m_cache[key] = value; 47 } 48 49protected: 50 Connection(boost::shared_ptr<Stream> stream); 51 52 boost::shared_ptr<Stream> getStream(const GeneralHeaders &general, 53 const EntityHeaders &entity, 54 const std::string &method, 55 Status status, 56 boost::function<void ()> notifyOnEof, 57 boost::function<void ()> notifyOnException, 58 bool forRead); 59 60protected: 61 boost::shared_ptr<Stream> m_stream; 62 63private: 64 boost::mutex m_cacheMutex; 65 anymap m_cache; 66}; 67 68}} 69 70#endif