Panda3D
Loading...
Searching...
No Matches
datagramQueue.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 datagramQueue.h
10 * @author drose
11 * @date 2000-02-07
12 */
13
14#ifndef DATAGRAMQUEUE_H
15#define DATAGRAMQUEUE_H
16
17#include "pandabase.h"
18
19#include "netDatagram.h"
20#include "pmutex.h"
21#include "conditionVarFull.h"
22#include "pdeque.h"
23
24/**
25 * A thread-safe, FIFO queue of NetDatagrams. This is used by
26 * ConnectionWriter for queuing up datagrams for its various threads to write
27 * to sockets.
28 */
29class EXPCL_PANDA_NET DatagramQueue {
30public:
31 DatagramQueue();
32 ~DatagramQueue();
33 void shutdown();
34
35 bool insert(const NetDatagram &data, bool block = false);
36 bool extract(NetDatagram &result);
37
38 void set_max_queue_size(int max_size);
39 int get_max_queue_size() const;
40 int get_current_queue_size() const;
41
42private:
43 Mutex _cvlock;
44 ConditionVarFull _cv; // signaled when queue contents change.
45
46 typedef pdeque<NetDatagram> QueueType;
47 QueueType _queue;
48 bool _shutdown;
49 int _max_queue_size;
50};
51
52#endif
This class implements a condition variable; see ConditionVar for a brief introduction to this class.
int get_max_queue_size() const
Returns the maximum size the queue is allowed to grow to.
void shutdown()
Marks the queue as shutting down, which will eventually cause all threads blocking on extract() to re...
void set_max_queue_size(int max_size)
Sets the maximum size the queue is allowed to grow to.
bool extract(NetDatagram &result)
Extracts a datagram from the head of the queue, if one is available.
bool insert(const NetDatagram &data, bool block=false)
Inserts the indicated datagram onto the end of the queue, and returns.
int get_current_queue_size() const
Returns the current number of things in the queue.
A standard mutex, or mutual exclusion lock.
Definition pmutex.h:40
A specific kind of Datagram, especially for sending across or receiving from a network.
Definition netDatagram.h:40
This is our own Panda specialization on the default STL deque.
Definition pdeque.h:36
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.