OpenTTD: PacketWriter Struct Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- Data Structures
- Class Hierarchy
- Data Fields

Public Member Functions | Data Fields
PacketWriter Struct Reference

Writing a savegame directly to a number of packets. More...

Inheritance diagram for PacketWriter:

## Public Member Functions
| PacketWriter (ServerNetworkGameSocketHandler *cs)
| Create the packet writer.
| ~PacketWriter ()
| Make sure everything is cleaned up.
void | Destroy ()
| Begin the destruction of this packet writer.
bool | HasPackets ()
| Checks whether there are packets.
Packet * | PopPacket ()
| Pop a single created packet from the queue with packets.
void | AppendQueue ()
| Append the current packet to the queue.
void | Write (byte *buf, size_t size)
| Write a given number of bytes into the savegame.
void | Finish ()
| Prepare everything to finish writing the savegame.
Public Member Functions inherited from SaveFilter
| SaveFilter (SaveFilter *chain)
| Initialise this filter.
virtual | ~SaveFilter ()
| Make sure the writers are properly closed.

## Data Fields
ServerNetworkGameSocketHandler * | cs
| Socket we are associated with.
Packet * | current
| The packet we're currently writing to.
size_t | total_size
| Total size of the compressed savegame.
Packet * | packets
| Packet queue of the savegame; send these "slowly" to the client.
ThreadMutex * | mutex
| Mutex for making threaded saving safe.
Data Fields inherited from SaveFilter
SaveFilter * | chain
| Chained to the (savegame) filters.

## Detailed Description

Writing a savegame directly to a number of packets.

Definition at line 58 of file network_server.cpp.

## Constructor & Destructor Documentation

PacketWriter::PacketWriter | ( | ServerNetworkGameSocketHandler * | cs | ) |
| inline

Create the packet writer.

Parameters

  cs | The socket handler we're making the packets for.

Definition at line 69 of file network_server.cpp.

References ThreadMutex::New().

PacketWriter::~PacketWriter | ( |  | ) |
| inline

Make sure everything is cleaned up.

Definition at line 75 of file network_server.cpp.

References ThreadMutex::BeginCritical(), ThreadMutex::EndCritical(), Packet::next, and ThreadMutex::WaitForSignal().

## Member Function Documentation

void PacketWriter::AppendQueue | ( |  | ) |
| inline

Append the current packet to the queue.

Definition at line 155 of file network_server.cpp.

References Packet::next.

void PacketWriter::Destroy | ( |  | ) |
| inline

Begin the destruction of this packet writer.

It can happen in two ways: in the first case the client disconnected while saving the map. In this case the saving has not finished and killed this PacketWriter. In that case we simply set cs to NULL, triggering the appending to fail due to the connection problem and eventually triggering the destructor. In the second case the destructor is already called, and it is waiting for our signal which we will send. Only then the packets will be removed by the destructor.

Definition at line 109 of file network_server.cpp.

References ThreadMutex::BeginCritical(), ThreadMutex::EndCritical(), ProcessAsyncSaveFinish(), and ThreadMutex::SendSignal().

Referenced by ServerNetworkGameSocketHandler::SendMap(), and ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler().

bool PacketWriter::HasPackets | ( |  | ) |
| inline

Checks whether there are packets.

It's not 100% threading safe, but this is only asked for when checking whether there still is something to send. Then another call will be made to actually get the Packet, which will be the only one popping packets and thus eventually setting this on false.

Definition at line 133 of file network_server.cpp.

Referenced by ServerNetworkGameSocketHandler::SendMap().

void PacketWriter::Write | ( | byte * | buf,
|  | size_t | len
| ) |  |
| inlinevirtual

Write a given number of bytes into the savegame.

Parameters

  buf | The bytes to write.
  len | The number of bytes to write.

Implements SaveFilter.

Definition at line 168 of file network_server.cpp.

References ThreadMutex::BeginCritical(), Packet::buffer, ThreadMutex::EndCritical(), min(), PACKET_SERVER_MAP_DATA, SEND_MTU, Packet::size, and SlError().

The documentation for this struct was generated from the following file:

- src/network/network_server.cpp