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

Method SendDataThroughSocket

src/OSSupport/SocketThreads.cpp:605–631  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

603
604
605bool cSocketThreads::cSocketThread::SendDataThroughSocket(cSocket & a_Socket, AString & a_Data)
606{
607 // Send data in smaller chunks, so that the OS send buffers aren't overflown easily
608 while (!a_Data.empty())
609 {
610 size_t NumToSend = std::min(a_Data.size(), (size_t)1024);
611 int Sent = a_Socket.Send(a_Data.data(), NumToSend);
612 if (Sent < 0)
613 {
614 int Err = cSocket::GetLastError();
615 if (Err == cSocket::ErrWouldBlock)
616 {
617 // The OS send buffer is full, leave the outgoing data for the next time
618 return true;
619 }
620 // An error has occured
621 return false;
622 }
623 if (Sent == 0)
624 {
625 a_Socket.CloseSocket();
626 return true;
627 }
628 a_Data.erase(0, Sent);
629 }
630 return true;
631}
632
633
634

Callers

nothing calls this directly

Calls 4

emptyMethod · 0.80
sizeMethod · 0.80
SendMethod · 0.45
CloseSocketMethod · 0.45

Tested by

no test coverage detected