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

Method DoUpload

src/Networking/HttpResponder.cpp:1390–1443  ·  view source on GitHub ↗

This function overrides the one in class NetworkResponder. It tries to process a chunk of uploaded data and changes the state if finished.

Source from the content-addressed store, hash-verified

1388// This function overrides the one in class NetworkResponder.
1389// It tries to process a chunk of uploaded data and changes the state if finished.
1390void HttpResponder::DoUpload() noexcept
1391{
1392 const uint8_t *_ecv_array buffer;
1393 size_t len;
1394 if (skt->ReadBuffer(buffer, len))
1395 {
1396 size_t bytesWritten = 0; // don't write than one FS buffer at once, else we may get stuck here with slow cards
1397 do
1398 {
1399 (void)CheckAuthenticated(); // uploading may take a long time, so make sure the requester IP is not timed out
1400 timer = millis(); // reset the timer
1401
1402 const bool ok = dummyUpload || fileBeingUploaded.Write(buffer, len);
1403 skt->Taken(len);
1404 uploadedBytes += len;
1405 bytesWritten += len;
1406
1407 if (!ok)
1408 {
1409 uploadError = true;
1410 GetPlatform().Message(ErrorMessage, "HTTP: could not write upload data\n");
1411 CancelUpload();
1412 SendJsonResponse("upload");
1413 return;
1414 }
1415 } while (bytesWritten < FileWriteBufLen && skt->ReadBuffer(buffer, len));
1416 }
1417 else if (!skt->CanRead() || millis() - timer >= HttpSessionTimeout)
1418 {
1419 // Sometimes uploads can get stuck; make sure they are cancelled when that happens
1420 ConnectionLost();
1421 return;
1422 }
1423
1424 // See if the upload has finished
1425 if (uploadedBytes >= postFileLength)
1426 {
1427 // Reset POST upload state for this client
1428 const HttpSessionKey key = GetSessionKey();
1429 const IPAddress remoteIP = GetRemoteIP();
1430 for (size_t i = 0; i < numSessions; i++)
1431 {
1432 if (sessions[i].ip == remoteIP && sessions[i].key == key && sessions[i].isPostUploading)
1433 {
1434 sessions[i].isPostUploading = false;
1435 sessions[i].lastQueryTime = millis();
1436 break;
1437 }
1438 }
1439
1440 FinishUpload(postFileLength, fileLastModified, postFileGotCrc, postFileExpectedCrc);
1441 SendJsonResponse("upload");
1442 }
1443}
1444
1445#endif
1446

Callers

nothing calls this directly

Calls 5

MessageMethod · 0.80
WriteMethod · 0.60
ReadBufferMethod · 0.45
TakenMethod · 0.45
CanReadMethod · 0.45

Tested by

no test coverage detected