pion-net  4.0.9
TCPTimer.hpp
1 // ------------------------------------------------------------------
2 // pion-net: a C++ framework for building lightweight HTTP interfaces
3 // ------------------------------------------------------------------
4 // Copyright (C) 2007-2010 Atomic Labs, Inc. (http://www.atomiclabs.com)
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // See http://www.boost.org/LICENSE_1_0.txt
8 //
9 
10 #ifndef __PION_TCPTIMER_HEADER__
11 #define __PION_TCPTIMER_HEADER__
12 
13 #include <boost/asio.hpp>
14 #include <boost/shared_ptr.hpp>
15 #include <boost/enable_shared_from_this.hpp>
16 #include <boost/thread/mutex.hpp>
17 #include <pion/PionConfig.hpp>
18 #include <pion/net/TCPConnection.hpp>
19 
20 
21 namespace pion { // begin namespace pion
22 namespace net { // begin namespace net (Pion Network Library)
23 
24 
28 class TCPTimer
29  : public boost::enable_shared_from_this<TCPTimer>
30 {
31 public:
32 
38  TCPTimer(TCPConnectionPtr& conn_ptr);
39 
45  void start(const boost::uint32_t seconds);
46 
48  void cancel(void);
49 
50 
51 private:
52 
58  void timerCallback(const boost::system::error_code& ec);
59 
60 
62  TCPConnectionPtr m_conn_ptr;
63 
65  boost::asio::deadline_timer m_timer;
66 
68  boost::mutex m_mutex;
69 
71  bool m_timer_active;
72 
74  bool m_was_cancelled;
75 };
76 
77 
79 typedef boost::shared_ptr<TCPTimer> TCPTimerPtr;
80 
81 
82 } // end namespace net
83 } // end namespace pion
84 
85 #endif
TCPTimer(TCPConnectionPtr &conn_ptr)
Definition: TCPTimer.cpp:20
void start(const boost::uint32_t seconds)
Definition: TCPTimer.cpp:26
void cancel(void)
cancel the timer (operation completed)
Definition: TCPTimer.cpp:35