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

Method SendGCodeReply

src/Networking/HttpResponder.cpp:1012–1060  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1010}
1011
1012void HttpResponder::SendGCodeReply() noexcept
1013{
1014 {
1015 // Do we need to keep the G-Code reply for other clients?
1016 bool clearReply = false;
1017 MutexLocker Lock(gcodeReplyMutex);
1018
1019 if (!gcodeReply.IsEmpty())
1020 {
1021 clientsServed++;
1022 if (clientsServed < numSessions)
1023 {
1024 // Yes - make sure the Network class doesn't discard its buffers yet
1025 // NB: This must happen here, because NetworkTransaction::Write() might already release OutputBuffers
1026 gcodeReply.IncreaseReferences(1);
1027 }
1028 else
1029 {
1030 // No - clean up again later
1031 clearReply = true;
1032 }
1033
1034 if (reprap.Debug(Module::Webserver))
1035 {
1036 GetPlatform().MessageF(UsbMessage, "Sending G-Code reply to HTTP client %d of %d (length %u)\n", clientsServed, numSessions, gcodeReply.DataLength());
1037 }
1038 }
1039
1040 // Send the whole G-Code reply as plain text to the client
1041 outBuf->copy( "HTTP/1.1 200 OK\r\n"
1042 "Cache-Control: no-cache, no-store, must-revalidate\r\n"
1043 "Pragma: no-cache\r\n"
1044 "Expires: 0\r\n"
1045 "Content-Type: text/plain\r\n"
1046 );
1047 outBuf->catf("Content-Length: %u\r\n", gcodeReply.DataLength());
1048 AddCorsHeader();
1049 outBuf->cat("Connection: close\r\n\r\n");
1050 outStack.Append(gcodeReply);
1051
1052 // Possibly clean up the G-code reply once again
1053 if (clearReply)
1054 {
1055 gcodeReply.Clear();
1056 }
1057 }
1058
1059 Commit();
1060}
1061
1062// Send a JSON response to the current command. outBuf is non-null on entry.
1063void HttpResponder::SendJsonResponse(const char *_ecv_array command) noexcept

Callers

nothing calls this directly

Calls 10

IncreaseReferencesMethod · 0.80
DebugMethod · 0.80
copyMethod · 0.80
catfMethod · 0.80
catMethod · 0.80
AppendMethod · 0.80
IsEmptyMethod · 0.45
MessageFMethod · 0.45
DataLengthMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected