Panda3D
Loading...
Searching...
No Matches
connectionWriter.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file connectionWriter.h
10 * @author drose
11 * @date 2000-02-08
12 */
13
14#ifndef CONNECTIONWRITER_H
15#define CONNECTIONWRITER_H
16
17#include "pandabase.h"
18#include "datagramQueue.h"
19#include "connection.h"
20#include "pointerTo.h"
21#include "thread.h"
22#include "pvector.h"
23
25class NetAddress;
26
27/**
28 * This class handles threaded delivery of datagrams to various TCP or UDP
29 * sockets.
30 *
31 * A ConnectionWriter may define an arbitrary number of threads (0 or more) to
32 * write its datagrams to sockets. The number of threads is specified at
33 * construction time and cannot be changed.
34 */
35class EXPCL_PANDA_NET ConnectionWriter {
36PUBLISHED:
37 explicit ConnectionWriter(ConnectionManager *manager, int num_threads,
38 const std::string &thread_name = std::string());
40
41 void set_max_queue_size(int max_size);
42 int get_max_queue_size() const;
43 int get_current_queue_size() const;
44
45 BLOCKING bool send(const Datagram &datagram,
46 const PT(Connection) &connection,
47 bool block = false);
48
49 BLOCKING bool send(const Datagram &datagram,
50 const PT(Connection) &connection,
51 const NetAddress &address,
52 bool block = false);
53
54 bool is_valid_for_udp(const Datagram &datagram) const;
55
56 ConnectionManager *get_manager() const;
57 bool is_immediate() const;
58 int get_num_threads() const;
59
60 void set_raw_mode(bool mode);
61 bool get_raw_mode() const;
62
63 void set_tcp_header_size(int tcp_header_size);
64 int get_tcp_header_size() const;
65
66 void shutdown();
67
68protected:
69 void clear_manager();
70
71private:
72 void thread_run(int thread_index);
73 bool send_datagram(const NetDatagram &datagram);
74
75protected:
76 ConnectionManager *_manager;
77
78private:
79 bool _raw_mode;
80 int _tcp_header_size;
81 DatagramQueue _queue;
82 bool _shutdown;
83
84 class WriterThread : public Thread {
85 public:
86 WriterThread(ConnectionWriter *writer, const std::string &thread_name,
87 int thread_index);
88 virtual void thread_main();
89
90 ConnectionWriter *_writer;
91 int _thread_index;
92 };
93
94 typedef pvector< PT(WriterThread) > Threads;
95 Threads _threads;
96
97 bool _immediate;
98
99 friend class ConnectionManager;
100 friend class WriterThread;
101};
102
103#endif
The primary interface to the low-level networking layer in this package.
void set_max_queue_size(int max_size)
Limits the number of packets that may be pending on the outbound queue.
int get_num_threads() const
Returns the number of threads the ConnectionWriter has been created with.
bool send(const Datagram &datagram, const PT(Connection) &connection, bool block=false)
Enqueues a datagram for transmittal on the indicated socket.
bool is_valid_for_udp(const Datagram &datagram) const
Returns true if the datagram is small enough to be sent over a UDP packet, false otherwise.
void set_raw_mode(bool mode)
Sets the ConnectionWriter into raw mode (or turns off raw mode).
void shutdown()
Stops all the threads and cleans them up.
int get_max_queue_size() const
Returns the maximum size the queue is allowed to grow to.
bool is_immediate() const
Returns true if the writer is an immediate writer, i.e.
ConnectionManager * get_manager() const
Returns a pointer to the ConnectionManager object that serves this ConnectionWriter.
bool get_raw_mode() const
Returns the current setting of the raw mode flag.
ConnectionWriter(ConnectionManager *manager, int num_threads, const std::string &thread_name=std::string())
Creates a new ConnectionWriter with the indicated number of threads to handle output.
int get_current_queue_size() const
Returns the current number of things in the queue.
int get_tcp_header_size() const
Returns the current setting of TCP header size.
void set_tcp_header_size(int tcp_header_size)
Sets the header size of TCP packets.
A thread-safe, FIFO queue of NetDatagrams.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound.
Definition netAddress.h:25
A specific kind of Datagram, especially for sending across or receiving from a network.
Definition netDatagram.h:40
A thread; that is, a lightweight process.
Definition thread.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.