ircproxy The Ultimate Cyborg |
00001 // ircproxy -- An IRC bouncer. 00002 // 00003 //! @file Queue.h 00004 //! @brief This file contains the declaration of class Queue. 00005 // 00006 // Copyright (C) 2007 by 00007 // 00008 // Carlo Wood, Run on IRC <carlo@alinoe.com> 00009 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 00010 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 00011 // 00012 // This file may be distributed under the terms of the Q Public License 00013 // version 1.0 as appearing in the file LICENSE.QPL included in the 00014 // packaging of this file. 00015 00016 #ifndef QUEUE_H 00017 #define QUEUE_H 00018 00019 #ifndef USE_PCH 00020 #include <queue> 00021 #include "debug.h" 00022 #endif 00023 00024 #include "MessageOut.h" 00025 #include "IdentityReference.h" 00026 00027 //! @brief A queue for messages to be sent to the server. 00028 // 00029 // Every second M_messages_per_second can be sent. 00030 // This is achieved by incrementing M_free_messages with elapsed_seconds * M_messages_per_second, 00031 // with an upper limit of M_max_free_messages. 00032 // Each time a message is sent, M_free_messages is decremented with one. 00033 class Queue : public virtual event_client_ct { 00034 public: 00035 //! The type of the outgoing messages queue. 00036 typedef std::priority_queue<MessageOut, std::deque<MessageOut> > priority_queue_type; 00037 00038 private: 00039 ServerConnection& M_server_connection; //!< Reference to the underlying server connection. 00040 priority_queue_type M_priority_queue; //!< A queue for output messages, sorted by priority, that are waiting to be sent. 00041 float const M_messages_per_second; //!< The maximum average number of messages per second that can be sent to the server. 00042 unsigned int const M_max_free_messages; //!< The maximum number of message that can be sent in a single burst to the server. 00043 float M_free_messages; //!< The current number of messages that can be sent in a single burst. 00044 timeval M_time; //!< The last time that M_free_messages was updated. 00045 00046 public: 00047 //! Construct a Queue object. 00048 Queue(ServerConnection& server_connection, float messages_per_second, unsigned int max_free_messages, unsigned int initial_free_messages) : 00049 event_client_ct(), M_server_connection(server_connection), 00050 M_messages_per_second(messages_per_second), M_max_free_messages(max_free_messages), 00051 M_free_messages(initial_free_messages), M_time(timer_event_server_ct::instance().get_now()) { } 00052 ~Queue() { cancel_all_requests(); } 00053 00054 private: 00055 //! Flush output messages if possible. 00056 void flush(void); 00057 void send_next_message(timer_event_type_ct const&); 00058 00059 public: 00060 //! Send or queue an output message. 00061 void queue_msg(MessageOut const& message_out) { M_priority_queue.push(message_out); this->flush(); } 00062 }; 00063 00064 #endif // QUEUE_H
Copyright © 2005-2007 Carlo Wood. All rights reserved. |
---|