| 142 | } |
| 143 | |
| 144 | void Write(uint8_t *buf, size_t size) override |
| 145 | { |
| 146 | std::lock_guard<std::mutex> lock(this->mutex); |
| 147 | |
| 148 | /* We want to abort the saving when the socket is closed. */ |
| 149 | if (this->cs == nullptr) SlError(STR_NETWORK_ERROR_LOSTCONNECTION); |
| 150 | |
| 151 | if (this->current == nullptr) this->current = std::make_unique<Packet>(this->cs, PACKET_SERVER_MAP_DATA, TCP_MTU); |
| 152 | |
| 153 | std::span<const uint8_t> to_write(buf, size); |
| 154 | while (!to_write.empty()) { |
| 155 | to_write = this->current->Send_bytes(to_write); |
| 156 | |
| 157 | if (!this->current->CanWriteToPacket(1)) { |
| 158 | this->packets.push_back(std::move(this->current)); |
| 159 | if (!to_write.empty()) this->current = std::make_unique<Packet>(this->cs, PACKET_SERVER_MAP_DATA, TCP_MTU); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | this->total_size += size; |
| 164 | } |
| 165 | |
| 166 | void Finish() override |
| 167 | { |
nothing calls this directly
no test coverage detected