From 197d2b968cb1c1e8615baea8c785e86d35327068 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 19 Oct 2020 17:23:13 +0200 Subject: [PATCH] Tiny changes in the new Duet3D dsf support code --- src/slic3r/Utils/Duet.cpp | 4 ++++ src/slic3r/Utils/Duet.hpp | 2 +- src/slic3r/Utils/Http.cpp | 12 +++++------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/slic3r/Utils/Duet.cpp b/src/slic3r/Utils/Duet.cpp index 4a510bb04..ba93603a1 100644 --- a/src/slic3r/Utils/Duet.cpp +++ b/src/slic3r/Utils/Duet.cpp @@ -177,6 +177,8 @@ void Duet::disconnect(ConnectionType connectionType) const std::string Duet::get_upload_url(const std::string &filename, ConnectionType connectionType) const { + assert(connectionType != ConnectionType::error); + if (connectionType == ConnectionType::dsf) { return (boost::format("%1%machine/file/gcodes/%2%") % get_base_url() @@ -230,6 +232,8 @@ std::string Duet::timestamp_str() const bool Duet::start_print(wxString &msg, const std::string &filename, ConnectionType connectionType) const { + assert(connectionType != ConnectionType::error); + bool res = false; bool dsf = (connectionType == ConnectionType::dsf); diff --git a/src/slic3r/Utils/Duet.hpp b/src/slic3r/Utils/Duet.hpp index 597df02b3..7fdd8ea10 100644 --- a/src/slic3r/Utils/Duet.hpp +++ b/src/slic3r/Utils/Duet.hpp @@ -14,7 +14,7 @@ class Http; class Duet : public PrintHost { public: - Duet(DynamicPrintConfig *config); + explicit Duet(DynamicPrintConfig *config); ~Duet() override = default; const char* get_name() const override; diff --git a/src/slic3r/Utils/Http.cpp b/src/slic3r/Utils/Http.cpp index a8a34784a..7674ee76e 100644 --- a/src/slic3r/Utils/Http.cpp +++ b/src/slic3r/Utils/Http.cpp @@ -120,7 +120,7 @@ struct Http::priv std::string error_buffer; // Used for CURLOPT_ERRORBUFFER size_t limit; bool cancel; - fs::ifstream* putFile; + std::unique_ptr putFile; std::thread io_thread; Http::CompleteFn completefn; @@ -298,8 +298,8 @@ void Http::priv::set_put_body(const fs::path &path) boost::system::error_code ec; boost::uintmax_t filesize = file_size(path, ec); if (!ec) { - putFile = new fs::ifstream(path); - ::curl_easy_setopt(curl, CURLOPT_READDATA, (void *) (putFile)); + putFile = std::make_unique(path); + ::curl_easy_setopt(curl, CURLOPT_READDATA, (void *) (putFile.get())); ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, filesize); } } @@ -355,10 +355,7 @@ void Http::priv::http_perform() CURLcode res = ::curl_easy_perform(curl); - if (putFile != nullptr) { - delete putFile; - putFile = nullptr; - } + putFile.reset(); if (res != CURLE_OK) { if (res == CURLE_ABORTED_BY_CALLBACK) { @@ -398,6 +395,7 @@ Http::Http(Http &&other) : p(std::move(other.p)) {} Http::~Http() { + assert(! putFile); if (p && p->io_thread.joinable()) { p->io_thread.detach(); }