| 174 | } |
| 175 | |
| 176 | PacketBuffer* ReliablePacketList::compact(PacketBuffer* into, PacketBuffer* end) { |
| 177 | ReliablePacket* r = reliable.next; |
| 178 | while (r != &reliable) { |
| 179 | for (ReliablePacket* c = r; c; c = c->cont) { |
| 180 | if (c->buffer == end /*&& c->begin>=c->buffer->bytes_written*/) // quit when we hit the unsent range |
| 181 | return into; |
| 182 | if (into->bytes_written == into->size()) { |
| 183 | into->next = PacketBuffer::create(into->size()); |
| 184 | into = into->nextPacketBuffer(); |
| 185 | } |
| 186 | |
| 187 | uint8_t* data = &c->buffer->data()[c->begin]; |
| 188 | int len = c->end - c->begin; |
| 189 | |
| 190 | if (len > into->bytes_unwritten()) { |
| 191 | // We have to split this ReliablePacket |
| 192 | len = into->bytes_unwritten(); |
| 193 | ReliablePacket* e = new ReliablePacket; |
| 194 | e->cont = c->cont; |
| 195 | e->buffer = c->buffer; |
| 196 | e->buffer->addref(); |
| 197 | e->begin = c->begin + len; |
| 198 | e->end = c->end; |
| 199 | c->cont = e; |
| 200 | } |
| 201 | |
| 202 | memcpy(into->data() + into->bytes_written, data, len); |
| 203 | c->buffer->delref(); |
| 204 | c->buffer = into; |
| 205 | c->buffer->addref(); |
| 206 | c->begin = into->bytes_written; |
| 207 | into->bytes_written += len; |
| 208 | c->end = into->bytes_written; |
| 209 | } |
| 210 | |
| 211 | r = r->next; |
| 212 | } |
| 213 | return into; |
| 214 | } |
| 215 | |
| 216 | void ReliablePacketList::discardAll() { |
| 217 | while (reliable.next != &reliable) |
no test coverage detected