MCPcopy Create free account
hub / github.com/cuberite/cuberite / WriteBuf

Method WriteBuf

src/ByteBuffer.cpp:695–719  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

693
694
695bool cByteBuffer::WriteBuf(const void * a_Buffer, size_t a_Count)
696{
697 CHECK_THREAD;
698 CheckValid();
699 PUTBYTES(a_Count);
700 char * Src = (char *)a_Buffer; // So that we can do byte math
701 ASSERT(m_BufferSize >= m_ReadPos);
702 size_t BytesToEndOfBuffer = m_BufferSize - m_WritePos;
703 if (BytesToEndOfBuffer <= a_Count)
704 {
705 // Reading across the ringbuffer end, read the first part and adjust parameters:
706 memcpy(m_Buffer + m_WritePos, Src, BytesToEndOfBuffer);
707 Src += BytesToEndOfBuffer;
708 a_Count -= BytesToEndOfBuffer;
709 m_WritePos = 0;
710 }
711
712 // Read the rest of the bytes in a single read (guaranteed to fit):
713 if (a_Count > 0)
714 {
715 memcpy(m_Buffer + m_WritePos, Src, a_Count);
716 m_WritePos += a_Count;
717 }
718 return true;
719}
720
721
722

Callers 2

SendPacketMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected