00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CONNECTIONWRITER_H
00020 #define CONNECTIONWRITER_H
00021
00022 #include <pandabase.h>
00023
00024 #include "datagramQueue.h"
00025 #include "connection.h"
00026
00027 #include <pointerTo.h>
00028
00029 #include <prthread.h>
00030 #include "pvector.h"
00031
00032 class ConnectionManager;
00033 class NetAddress;
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 class EXPCL_PANDA ConnectionWriter {
00046 PUBLISHED:
00047 ConnectionWriter(ConnectionManager *manager, int num_threads);
00048 ~ConnectionWriter();
00049
00050 bool send(const Datagram &datagram,
00051 const PT(Connection) &connection);
00052
00053 bool send(const Datagram &datagram,
00054 const PT(Connection) &connection,
00055 const NetAddress &address);
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 protected:
00067 void clear_manager();
00068
00069 private:
00070 static void thread_start(void *data);
00071 void thread_run();
00072 bool send_datagram(const NetDatagram &datagram);
00073
00074 protected:
00075 ConnectionManager *_manager;
00076
00077 private:
00078 bool _raw_mode;
00079 DatagramQueue _queue;
00080
00081 typedef pvector<PRThread *> Threads;
00082 Threads _threads;
00083 bool _immediate;
00084
00085 friend class ConnectionManager;
00086 };
00087
00088 #endif
00089
00090