Panda3D

Public Member Functions | List of all members
DatagramQueue Class Reference

A thread-safe, FIFO queue of NetDatagrams. More...

`#include "datagramQueue.h"`

## Public Member Functions
bool | extract (NetDatagram &result)
| Extracts a datagram from the head of the queue, if one is available. More...
int | get_current_queue_size () const
| Returns the current number of things in the queue. More...
int | get_max_queue_size () const
| Returns the maximum size the queue is allowed to grow to. More...
bool | insert (const NetDatagram &data, bool block=false)
| Inserts the indicated datagram onto the end of the queue, and returns. More...
void | set_max_queue_size (int max_size)
| Sets the maximum size the queue is allowed to grow to. More...
void | shutdown ()
| Marks the queue as shutting down, which will eventually cause all threads blocking on extract() to return false. More...

## Detailed Description

A thread-safe, FIFO queue of NetDatagrams.

This is used by ConnectionWriter for queuing up datagrams for its various threads to write to sockets.

Definition at line 29 of file datagramQueue.h.

## Member Function Documentation

## ◆ extract()

bool DatagramQueue::extract | ( | NetDatagram & | result | ) |

Extracts a datagram from the head of the queue, if one is available.

If a datagram is available, this will immediately return; otherwise, it will block until a datagram becomes available. Multiple threads may simultaneously block on extract(); when a datagram is subsequently inserted into the queue, one of the threads will return from extract() with the datagram.

The return value is true if the datagram is successfully extracted, or false if the queue was destroyed while waiting. (In the case of a false return, the thread should not attempt to operate on the queue again.)

Definition at line 98 of file datagramQueue.cxx.

References NetDatagram::clear(), and ConditionVarFullDirect::wait().

## ◆ get_current_queue_size()

int DatagramQueue::get_current_queue_size | ( |  | ) | const

Returns the current number of things in the queue.

Definition at line 150 of file datagramQueue.cxx.

Referenced by ConnectionWriter::get_current_queue_size().

## ◆ get_max_queue_size()

int DatagramQueue::get_max_queue_size | ( |  | ) | const

Returns the maximum size the queue is allowed to grow to.

See set_max_queue_size().

Definition at line 142 of file datagramQueue.cxx.

Referenced by ConnectionWriter::get_max_queue_size().

## ◆ insert()

bool DatagramQueue::insert | ( | const NetDatagram & | data,
|  | bool | block = `false`
| ) |  |

Inserts the indicated datagram onto the end of the queue, and returns.

If the queue is empty and any threads are waiting on the queue, this will wake one of them up. Returns true if successful, false if the queue was full.

If block is true, this will not return until successful, waiting until the queue has space available if necessary.

Definition at line 65 of file datagramQueue.cxx.

## ◆ set_max_queue_size()

void DatagramQueue::set_max_queue_size | ( | int | max_size | ) |

Sets the maximum size the queue is allowed to grow to.

This is primarily for a sanity check; this is a limit beyond which we can assume something bad has happened.

It's also a crude check against unfortunate seg faults due to the queue filling up and quietly consuming all available memory.

Definition at line 132 of file datagramQueue.cxx.

Referenced by ConnectionWriter::set_max_queue_size().

## ◆ shutdown()

void DatagramQueue::shutdown | ( |  | ) |

Marks the queue as shutting down, which will eventually cause all threads blocking on extract() to return false.

The normal way to delete a DatagramQueue will be to call first shutdown() and then wait for all known threads to terminate. Then it is safe to delete the queue.

Definition at line 46 of file datagramQueue.cxx.

References ConditionVarFullDirect::notify_all().

Referenced by ConnectionWriter::shutdown().

The documentation for this class was generated from the following files:

- panda/src/net/datagramQueue.h
- panda/src/net/datagramQueue.cxx