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

Method SendData

src/ClientHandle.cpp:1535–1580  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1533
1534
1535void cClientHandle::SendData(const char * a_Data, size_t a_Size)
1536{
1537 if (m_HasSentDC)
1538 {
1539 // This could crash the client, because they've already unloaded the world etc., and suddenly a wild packet appears (#31)
1540 return;
1541 }
1542
1543 {
1544 cCSLock Lock(m_CSOutgoingData);
1545
1546 // _X 2012_09_06: We need an overflow buffer, usually when streaming the initial chunks
1547 if (m_OutgoingDataOverflow.empty())
1548 {
1549 // No queued overflow data; if this packet fits into the ringbuffer, put it in, otherwise put it in the overflow buffer:
1550 size_t CanFit = m_OutgoingData.GetFreeSpace();
1551 if (CanFit > a_Size)
1552 {
1553 CanFit = a_Size;
1554 }
1555 if (CanFit > 0)
1556 {
1557 m_OutgoingData.Write(a_Data, CanFit);
1558 }
1559 if (a_Size > CanFit)
1560 {
1561 m_OutgoingDataOverflow.append(a_Data + CanFit, a_Size - CanFit);
1562 }
1563 }
1564 else
1565 {
1566 // There is a queued overflow. Append to it, then send as much from its front as possible
1567 m_OutgoingDataOverflow.append(a_Data, a_Size);
1568 int CanFit = m_OutgoingData.GetFreeSpace();
1569 if (CanFit > 128)
1570 {
1571 // No point in moving the data over if it's not large enough - too much effort for too little an effect
1572 m_OutgoingData.Write(m_OutgoingDataOverflow.data(), CanFit);
1573 m_OutgoingDataOverflow.erase(0, CanFit);
1574 }
1575 }
1576 } // Lock(m_CSOutgoingData)
1577
1578 // Notify SocketThreads that we have something to write:
1579 cRoot::Get()->GetServer()->NotifyClientWrite(this);
1580}
1581
1582
1583

Callers

nothing calls this directly

Calls 5

emptyMethod · 0.80
GetFreeSpaceMethod · 0.80
NotifyClientWriteMethod · 0.80
GetServerMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected