OpenTTD Source 20241224-master-gf74b0cf984
|
Writing a savegame directly to a number of packets. More...
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 | TransferToNetworkQueue () |
Transfer all packets from here to the network's queue while holding the lock on our mutex. | |
void | Write (uint8_t *buf, size_t size) override |
Write a given number of bytes into the savegame. | |
void | Finish () override |
Prepare everything to finish writing the savegame. | |
Public Member Functions inherited from SaveFilter | |
SaveFilter (std::shared_ptr< SaveFilter > chain) | |
Initialise this filter. | |
virtual | ~SaveFilter ()=default |
Make sure the writers are properly closed. | |
Data Fields | |
ServerNetworkGameSocketHandler * | cs |
Socket we are associated with. | |
std::unique_ptr< Packet > | current |
The packet we're currently writing to. | |
size_t | total_size |
Total size of the compressed savegame. | |
std::deque< std::unique_ptr< Packet > > | packets |
Packet queue of the savegame; send these "slowly" to the client. Cannot be a std::queue as we want to push the map size packet in front of the data packets. | |
std::mutex | mutex |
Mutex for making threaded saving safe. | |
std::condition_variable | exit_sig |
Signal for threaded destruction of this packet writer. | |
Data Fields inherited from SaveFilter | |
std::shared_ptr< SaveFilter > | chain |
Chained to the (savegame) filters. | |
Writing a savegame directly to a number of packets.
Definition at line 67 of file network_server.cpp.
|
inline |
Create the packet writer.
cs | The socket handler we're making the packets for. |
Definition at line 79 of file network_server.cpp.
|
inline |
Make sure everything is cleaned up.
Definition at line 84 of file network_server.cpp.
References lock.
|
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 nullptr, 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 106 of file network_server.cpp.
References lock.
|
inlineoverridevirtual |
Prepare everything to finish writing the savegame.
Reimplemented from SaveFilter.
Definition at line 166 of file network_server.cpp.
References lock, PACKET_SERVER_MAP_DONE, PACKET_SERVER_MAP_SIZE, and SlError().
|
inline |
Transfer all packets from here to the network's queue while holding the lock on our mutex.
Definition at line 126 of file network_server.cpp.
References lock, PACKET_SERVER_MAP_DONE, and NetworkTCPSocketHandler::SendPacket().
|
inlineoverridevirtual |
Write a given number of bytes into the savegame.
buf | The bytes to write. |
len | The number of bytes to write. |
Implements SaveFilter.
Definition at line 144 of file network_server.cpp.
References lock, PACKET_SERVER_MAP_DATA, SlError(), and TCP_MTU.
ServerNetworkGameSocketHandler* PacketWriter::cs |
Socket we are associated with.
Definition at line 68 of file network_server.cpp.
std::unique_ptr<Packet> PacketWriter::current |
The packet we're currently writing to.
Definition at line 69 of file network_server.cpp.
std::condition_variable PacketWriter::exit_sig |
Signal for threaded destruction of this packet writer.
Definition at line 73 of file network_server.cpp.
std::mutex PacketWriter::mutex |
Mutex for making threaded saving safe.
Definition at line 72 of file network_server.cpp.
std::deque<std::unique_ptr<Packet> > PacketWriter::packets |
Packet queue of the savegame; send these "slowly" to the client. Cannot be a std::queue as we want to push the map size packet in front of the data packets.
Definition at line 71 of file network_server.cpp.
size_t PacketWriter::total_size |
Total size of the compressed savegame.
Definition at line 70 of file network_server.cpp.