<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[libtorrent - 200 Millisekunden Schlaf in Download-Schleife]]></title><description><![CDATA[<p>Hallo,</p>
<p>rasterbar schrieb:</p>
<blockquote>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;thread&gt;
#include &lt;chrono&gt;

#include &lt;libtorrent/session.hpp&gt;
#include &lt;libtorrent/add_torrent_params.hpp&gt;
#include &lt;libtorrent/torrent_handle.hpp&gt;
#include &lt;libtorrent/alert_types.hpp&gt;

namespace lt = libtorrent;
int main(int argc, char const* argv[])
{
  if (argc != 2) {
    std::cerr &lt;&lt; &quot;usage: &quot; &lt;&lt; argv[0] &lt;&lt; &quot; &lt;magnet-url&gt;&quot; &lt;&lt; std::endl;
    return 1;
  }
  lt::session ses;

  lt::add_torrent_params atp;
  atp.url = argv[1];
  atp.save_path = &quot;.&quot;; // save in current dir
  lt::torrent_handle h = ses.add_torrent(atp);

  for (;;) {
    std::vector&lt;lt::alert*&gt; alerts;
    ses.pop_alerts(&amp;alerts);

    for (lt::alert const* a : alerts) {
      std::cout &lt;&lt; a-&gt;message() &lt;&lt; std::endl;
      // if we receive the finished alert or an error, we're done
      if (lt::alert_cast&lt;lt::torrent_finished_alert&gt;(a)) {
        goto done;
      }
      if (lt::alert_cast&lt;lt::torrent_error_alert&gt;(a)) {
        goto done;
      }
    }
    std::this_thread::sleep_for(std::chrono::milliseconds(200));
  }
  done:
  std::cout &lt;&lt; &quot;done, shutting down&quot; &lt;&lt; std::endl;
}
</code></pre>
</blockquote>
<p>Warum wird hier in Zeile 38 ein Timeout gemacht?<br />
Hat das überhaupt einen Sinn?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/339610/libtorrent-200-millisekunden-schlaf-in-download-schleife</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 23:19:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/339610.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 13 Sep 2016 14:32:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to libtorrent - 200 Millisekunden Schlaf in Download-Schleife on Tue, 13 Sep 2016 14:32:50 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>rasterbar schrieb:</p>
<blockquote>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;thread&gt;
#include &lt;chrono&gt;

#include &lt;libtorrent/session.hpp&gt;
#include &lt;libtorrent/add_torrent_params.hpp&gt;
#include &lt;libtorrent/torrent_handle.hpp&gt;
#include &lt;libtorrent/alert_types.hpp&gt;

namespace lt = libtorrent;
int main(int argc, char const* argv[])
{
  if (argc != 2) {
    std::cerr &lt;&lt; &quot;usage: &quot; &lt;&lt; argv[0] &lt;&lt; &quot; &lt;magnet-url&gt;&quot; &lt;&lt; std::endl;
    return 1;
  }
  lt::session ses;

  lt::add_torrent_params atp;
  atp.url = argv[1];
  atp.save_path = &quot;.&quot;; // save in current dir
  lt::torrent_handle h = ses.add_torrent(atp);

  for (;;) {
    std::vector&lt;lt::alert*&gt; alerts;
    ses.pop_alerts(&amp;alerts);

    for (lt::alert const* a : alerts) {
      std::cout &lt;&lt; a-&gt;message() &lt;&lt; std::endl;
      // if we receive the finished alert or an error, we're done
      if (lt::alert_cast&lt;lt::torrent_finished_alert&gt;(a)) {
        goto done;
      }
      if (lt::alert_cast&lt;lt::torrent_error_alert&gt;(a)) {
        goto done;
      }
    }
    std::this_thread::sleep_for(std::chrono::milliseconds(200));
  }
  done:
  std::cout &lt;&lt; &quot;done, shutting down&quot; &lt;&lt; std::endl;
}
</code></pre>
</blockquote>
<p>Warum wird hier in Zeile 38 ein Timeout gemacht?<br />
Hat das überhaupt einen Sinn?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2508498</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2508498</guid><dc:creator><![CDATA[rasterraster]]></dc:creator><pubDate>Tue, 13 Sep 2016 14:32:50 GMT</pubDate></item><item><title><![CDATA[Reply to libtorrent - 200 Millisekunden Schlaf in Download-Schleife on Tue, 13 Sep 2016 15:06:33 GMT]]></title><description><![CDATA[<p>Naja, das is ne Endlosschleife die was pollt so wie ich das sehe.<br />
Wenn Du da nicht 100% Prozessorauslastung willst gebietet es der Anstand dass man den Thread immer mal wieder schlafen schickt, damit der OS Task Scheduler (oder wie auch immer das Ding heisst) auch mal andere zum Zug kommen lässt ohne gleich böse (preemptive) werden zu müssen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2508509</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2508509</guid><dc:creator><![CDATA[scrontch]]></dc:creator><pubDate>Tue, 13 Sep 2016 15:06:33 GMT</pubDate></item><item><title><![CDATA[Reply to libtorrent - 200 Millisekunden Schlaf in Download-Schleife on Tue, 13 Sep 2016 15:09:39 GMT]]></title><description><![CDATA[<p>In der Schleife wird doch nur auf das Ende des Download gewartet, ohne den Thread-Sleep würde ein Prozessor-Kern zu 100% ausgelastet (und den Download evtl. verlangsamen).</p>
<p>PS: Auf die &quot;goto&quot;-Zeilen gehe ich jetzt mal nicht ein <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2508511</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2508511</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Tue, 13 Sep 2016 15:09:39 GMT</pubDate></item><item><title><![CDATA[Reply to libtorrent - 200 Millisekunden Schlaf in Download-Schleife on Tue, 13 Sep 2016 15:26:56 GMT]]></title><description><![CDATA[<p>Ja, ich hab mir meine eigenen Klassen dazu geschrieben.</p>
<p>Könnten wir ne kleine Abstimmung machen?</p>
<p>Wer findet es besser...<br />
...den Thread schlafen zu lassen, um Auslastung zu sparen oder<br />
...nicht auf die Auslastung zu achten und somit den größten Download-Speed erreichen?</p>
<p>Oder was ist generell besser?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2508512</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2508512</guid><dc:creator><![CDATA[rasterraster]]></dc:creator><pubDate>Tue, 13 Sep 2016 15:26:56 GMT</pubDate></item><item><title><![CDATA[Reply to libtorrent - 200 Millisekunden Schlaf in Download-Schleife on Tue, 13 Sep 2016 15:51:03 GMT]]></title><description><![CDATA[<p>rasterraster schrieb:</p>
<blockquote>
<p>Ja, ich hab mir meine eigenen Klassen dazu geschrieben.</p>
<p>Könnten wir ne kleine Abstimmung machen?</p>
<p>Wer findet es besser...<br />
...den Thread schlafen zu lassen, um Auslastung zu sparen oder<br />
...nicht auf die Auslastung zu achten und somit den größten Download-Speed erreichen?</p>
<p>Oder was ist generell besser?</p>
</blockquote>
<p>Ich fürchte du verstehst da was nicht.<br />
Wie gesagt wurde, diese Schleife lädt nichts runter!<br />
Die wartet nur auf das Ende des Downloads - der wohl in einem anderen Thread läuft.<br />
Schlimmstenfalls wartest Du 200ms zu lang (auf das Ende).<br />
Ich denke deine Downloadzeiten werden um Grössenordnungen höher sein (Minuten?).<br />
Also spielt das keine Rolle.<br />
PS: Und ich würde kein Download-Zeugs tolerieren dass mir 100% CPU Kernauslastung erzeugt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2508516</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2508516</guid><dc:creator><![CDATA[scrontch]]></dc:creator><pubDate>Tue, 13 Sep 2016 15:51:03 GMT</pubDate></item><item><title><![CDATA[Reply to libtorrent - 200 Millisekunden Schlaf in Download-Schleife on Tue, 13 Sep 2016 15:57:22 GMT]]></title><description><![CDATA[<p>Ah Mist, ich hab dem Th69 nicht richtig zugelesen.<br />
Okay, es gibt also kein Performance-Leck und an Auslastung wird gespart.<br />
Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2508522</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2508522</guid><dc:creator><![CDATA[rasterraster]]></dc:creator><pubDate>Tue, 13 Sep 2016 15:57:22 GMT</pubDate></item></channel></rss>