PageRenderTime 98ms CodeModel.GetById 93ms RepoModel.GetById 0ms app.codeStats 0ms

/mordor/http/connection.h

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