| 237 | } |
| 238 | |
| 239 | void NetworkStream::WriteBytes(const void* data, uint32 bytes) |
| 240 | { |
| 241 | // Calculate current position |
| 242 | const uint32 position = GetPosition(); |
| 243 | |
| 244 | // Check if there is need to update a buffer size |
| 245 | if (_length - position < bytes) |
| 246 | { |
| 247 | // Perform reallocation |
| 248 | uint32 newLength = _length != 0 ? _length * 2 : 256; |
| 249 | while (newLength < position + bytes) |
| 250 | newLength *= 2; |
| 251 | PROFILE_MEM(Networking); |
| 252 | byte* newBuf = (byte*)Allocator::Allocate(newLength); |
| 253 | if (_buffer && _length) |
| 254 | Platform::MemoryCopy(newBuf, _buffer, _length); |
| 255 | if (_allocated) |
| 256 | Allocator::Free(_buffer); |
| 257 | |
| 258 | // Update state |
| 259 | _buffer = newBuf; |
| 260 | _length = newLength; |
| 261 | _position = _buffer + position; |
| 262 | _allocated = true; |
| 263 | } |
| 264 | |
| 265 | // Copy data |
| 266 | Platform::MemoryCopy(_position, data, bytes); |
| 267 | _position += bytes; |
| 268 | } |
no test coverage detected