MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / SendData

Method SendData

src/Networking/NetworkResponder.cpp:41–159  ·  view source on GitHub ↗

Send our data. We send outBuf first, then outStack, and finally fileBeingSent.

Source from the content-addressed store, hash-verified

39// Send our data.
40// We send outBuf first, then outStack, and finally fileBeingSent.
41void NetworkResponder::SendData() noexcept
42{
43 // Send our output buffer and output stack
44 while (!terminateResponder)
45 {
46 if (outBuf == nullptr)
47 {
48 outBuf = outStack.Pop();
49 if (outBuf == nullptr)
50 {
51 break;
52 }
53 }
54 const size_t bytesLeft = outBuf->BytesLeft();
55 if (bytesLeft == 0)
56 {
57 outBuf = OutputBuffer::Release(outBuf);
58 }
59 else
60 {
61 const size_t sent = skt->Send(reinterpret_cast<const uint8_t *_ecv_array>(outBuf->UnreadData()), bytesLeft);
62 if (sent == 0)
63 {
64 // Check whether the connection has been closed
65 if (!skt->CanSend())
66 {
67 // The connection has been lost or the other end has closed it
68 if (reprap.Debug(Module::Webserver))
69 {
70 debugPrintf("Can't send anymore\n");
71 }
72 ConnectionLost();
73 }
74 return;
75 }
76
77 outBuf->Taken(sent); // tell the output buffer how much data we have taken
78 if (sent < bytesLeft)
79 {
80 return;
81 }
82 outBuf = OutputBuffer::Release(outBuf);
83 }
84 }
85
86 // If we get here then there are no output buffers left to send
87
88#if HAS_MASS_STORAGE
89 // If we have a file to send, send it
90 if (fileBeingSent != nullptr && fileBuffer == nullptr)
91 {
92 fileBuffer = NetworkBuffer::Allocate();
93 if (fileBuffer == nullptr)
94 {
95 return; // no buffer available, try again later
96 }
97 }
98

Callers

nothing calls this directly

Calls 13

debugPrintfFunction · 0.85
DebugMethod · 0.80
RemainingMethod · 0.80
PopMethod · 0.45
BytesLeftMethod · 0.45
SendMethod · 0.45
UnreadDataMethod · 0.45
CanSendMethod · 0.45
TakenMethod · 0.45
IsEmptyMethod · 0.45
ReadFromFileMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected