Send our data. We send outBuf first, then outStack, and finally fileBeingSent.
| 39 | // Send our data. |
| 40 | // We send outBuf first, then outStack, and finally fileBeingSent. |
| 41 | void 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 |
nothing calls this directly
no test coverage detected