Panda3D
 All Classes Functions Variables Enumerations
connectionWriter.h
1 // Filename: connectionWriter.h
2 // Created by: drose (08Feb00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef CONNECTIONWRITER_H
16 #define CONNECTIONWRITER_H
17 
18 #include "pandabase.h"
19 #include "datagramQueue.h"
20 #include "connection.h"
21 #include "pointerTo.h"
22 #include "thread.h"
23 #include "pvector.h"
24 
25 class ConnectionManager;
26 class NetAddress;
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : ConnectionWriter
30 // Description : This class handles threaded delivery of datagrams to
31 // various TCP or UDP sockets.
32 //
33 // A ConnectionWriter may define an arbitrary number of
34 // threads (0 or more) to write its datagrams to
35 // sockets. The number of threads is specified at
36 // construction time and cannot be changed.
37 ////////////////////////////////////////////////////////////////////
38 class EXPCL_PANDA_NET ConnectionWriter {
39 PUBLISHED:
40  ConnectionWriter(ConnectionManager *manager, int num_threads,
41  const string &thread_name = string());
43 
44  void set_max_queue_size(int max_size);
45  int get_max_queue_size() const;
46  int get_current_queue_size() const;
47 
48  BLOCKING bool send(const Datagram &datagram,
49  const PT(Connection) &connection,
50  bool block = false);
51 
52  BLOCKING bool send(const Datagram &datagram,
53  const PT(Connection) &connection,
54  const NetAddress &address,
55  bool block = false);
56 
57  bool is_valid_for_udp(const Datagram &datagram) const;
58 
59  ConnectionManager *get_manager() const;
60  bool is_immediate() const;
61  int get_num_threads() const;
62 
63  void set_raw_mode(bool mode);
64  bool get_raw_mode() const;
65 
66  void set_tcp_header_size(int tcp_header_size);
67  int get_tcp_header_size() const;
68 
69  void shutdown();
70 
71 protected:
72  void clear_manager();
73 
74 private:
75  void thread_run(int thread_index);
76  bool send_datagram(const NetDatagram &datagram);
77 
78 protected:
79  ConnectionManager *_manager;
80 
81 private:
82  bool _raw_mode;
83  int _tcp_header_size;
84  DatagramQueue _queue;
85  bool _shutdown;
86 
87  class WriterThread : public Thread {
88  public:
89  WriterThread(ConnectionWriter *writer, const string &thread_name,
90  int thread_index);
91  virtual void thread_main();
92 
93  ConnectionWriter *_writer;
94  int _thread_index;
95  };
96 
98  Threads _threads;
99 
100  bool _immediate;
101 
102  friend class ConnectionManager;
103  friend class WriterThread;
104 };
105 
106 #endif
107 
108 
A specific kind of Datagram, especially for sending across or receiving from a network.
Definition: netDatagram.h:43
The primary interface to the low-level networking layer in this package.
This class handles threaded delivery of datagrams to various TCP or UDP sockets.
A thread; that is, a lightweight process.
Definition: thread.h:51
Represents a single TCP or UDP socket for input or output.
Definition: connection.h:32
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
A thread-safe, FIFO queue of NetDatagrams.
Definition: datagramQueue.h:31
Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound...
Definition: netAddress.h:27