00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CONNECTIONWRITER_H
00016 #define CONNECTIONWRITER_H
00017
00018 #include "pandabase.h"
00019 #include "datagramQueue.h"
00020 #include "connection.h"
00021 #include "pointerTo.h"
00022 #include "thread.h"
00023 #include "pvector.h"
00024
00025 class ConnectionManager;
00026 class NetAddress;
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 class EXPCL_PANDA_NET ConnectionWriter {
00039 PUBLISHED:
00040 ConnectionWriter(ConnectionManager *manager, int num_threads,
00041 const string &thread_name = string());
00042 ~ConnectionWriter();
00043
00044 void set_max_queue_size(int max_size);
00045 int get_max_queue_size() const;
00046 int get_current_queue_size() const;
00047
00048 BLOCKING bool send(const Datagram &datagram,
00049 const PT(Connection) &connection,
00050 bool block = false);
00051
00052 BLOCKING bool send(const Datagram &datagram,
00053 const PT(Connection) &connection,
00054 const NetAddress &address,
00055 bool block = false);
00056
00057 bool is_valid_for_udp(const Datagram &datagram) const;
00058
00059 ConnectionManager *get_manager() const;
00060 bool is_immediate() const;
00061 int get_num_threads() const;
00062
00063 void set_raw_mode(bool mode);
00064 bool get_raw_mode() const;
00065
00066 void set_tcp_header_size(int tcp_header_size);
00067 int get_tcp_header_size() const;
00068
00069 void shutdown();
00070
00071 protected:
00072 void clear_manager();
00073
00074 private:
00075 void thread_run(int thread_index);
00076 bool send_datagram(const NetDatagram &datagram);
00077
00078 protected:
00079 ConnectionManager *_manager;
00080
00081 private:
00082 bool _raw_mode;
00083 int _tcp_header_size;
00084 DatagramQueue _queue;
00085 bool _shutdown;
00086
00087 class WriterThread : public Thread {
00088 public:
00089 WriterThread(ConnectionWriter *writer, const string &thread_name,
00090 int thread_index);
00091 virtual void thread_main();
00092
00093 ConnectionWriter *_writer;
00094 int _thread_index;
00095 };
00096
00097 typedef pvector< PT(WriterThread) > Threads;
00098 Threads _threads;
00099
00100 bool _immediate;
00101
00102 friend class ConnectionManager;
00103 friend class WriterThread;
00104 };
00105
00106 #endif
00107
00108