Tiny changes in the new Duet3D dsf support code

This commit is contained in:
Lukas Matena 2020-10-19 17:23:13 +02:00
parent daeb618812
commit 197d2b968c
3 changed files with 10 additions and 8 deletions

View File

@ -177,6 +177,8 @@ void Duet::disconnect(ConnectionType connectionType) const
std::string Duet::get_upload_url(const std::string &filename, ConnectionType connectionType) const std::string Duet::get_upload_url(const std::string &filename, ConnectionType connectionType) const
{ {
assert(connectionType != ConnectionType::error);
if (connectionType == ConnectionType::dsf) { if (connectionType == ConnectionType::dsf) {
return (boost::format("%1%machine/file/gcodes/%2%") return (boost::format("%1%machine/file/gcodes/%2%")
% get_base_url() % 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 bool Duet::start_print(wxString &msg, const std::string &filename, ConnectionType connectionType) const
{ {
assert(connectionType != ConnectionType::error);
bool res = false; bool res = false;
bool dsf = (connectionType == ConnectionType::dsf); bool dsf = (connectionType == ConnectionType::dsf);

View File

@ -14,7 +14,7 @@ class Http;
class Duet : public PrintHost class Duet : public PrintHost
{ {
public: public:
Duet(DynamicPrintConfig *config); explicit Duet(DynamicPrintConfig *config);
~Duet() override = default; ~Duet() override = default;
const char* get_name() const override; const char* get_name() const override;

View File

@ -120,7 +120,7 @@ struct Http::priv
std::string error_buffer; // Used for CURLOPT_ERRORBUFFER std::string error_buffer; // Used for CURLOPT_ERRORBUFFER
size_t limit; size_t limit;
bool cancel; bool cancel;
fs::ifstream* putFile; std::unique_ptr<fs::ifstream> putFile;
std::thread io_thread; std::thread io_thread;
Http::CompleteFn completefn; Http::CompleteFn completefn;
@ -298,8 +298,8 @@ void Http::priv::set_put_body(const fs::path &path)
boost::system::error_code ec; boost::system::error_code ec;
boost::uintmax_t filesize = file_size(path, ec); boost::uintmax_t filesize = file_size(path, ec);
if (!ec) { if (!ec) {
putFile = new fs::ifstream(path); putFile = std::make_unique<fs::ifstream>(path);
::curl_easy_setopt(curl, CURLOPT_READDATA, (void *) (putFile)); ::curl_easy_setopt(curl, CURLOPT_READDATA, (void *) (putFile.get()));
::curl_easy_setopt(curl, CURLOPT_INFILESIZE, filesize); ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, filesize);
} }
} }
@ -355,10 +355,7 @@ void Http::priv::http_perform()
CURLcode res = ::curl_easy_perform(curl); CURLcode res = ::curl_easy_perform(curl);
if (putFile != nullptr) { putFile.reset();
delete putFile;
putFile = nullptr;
}
if (res != CURLE_OK) { if (res != CURLE_OK) {
if (res == CURLE_ABORTED_BY_CALLBACK) { if (res == CURLE_ABORTED_BY_CALLBACK) {
@ -398,6 +395,7 @@ Http::Http(Http &&other) : p(std::move(other.p)) {}
Http::~Http() Http::~Http()
{ {
assert(! putFile);
if (p && p->io_thread.joinable()) { if (p && p->io_thread.joinable()) {
p->io_thread.detach(); p->io_thread.detach();
} }