<?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[FD_CLOSE vor FD_READ]]></title><description><![CDATA[<p>Hallo,<br />
ich schreibe an einem Bot, der erst mal nix anderes machen soll, als seiten aus dem Netz runter zu laden. Das klappt auch schon alles ganz gut, nur hab ich jetzt folgendes Problem:<br />
Die Server senden auf meine Anfrage hin jeweils die Daten der ganzen Seite und schließen danach die Verbindung.<br />
Die ankommenden Daten verarbeite ich mit FD_READ und einem relativ kleinen Buffer von 1024 Byte und schreib sie dann in eine Datei.<br />
Jetzt passiert es aber, dass im Event-Handling der WinApi das FD_CLOSE-Event verarbeitet wird, bevor ich es geschafft hab alle Daten zu verarbeiten und da ich in FD_CLOSE die Verbindung schließe gehen mir dann Daten abhanden.</p>
<p>Ich müsste also irgendwie überprüfen können, ob noch FD_READ_Events in der Schleife sind, bevor ich die Verbindung schließe, aber ich hab keine Ahnung wie das gehen kann.</p>
<p>Bitte um Hilfe und Anregungen.</p>
<p>mfg<br />
Ingenuus</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/190534/fd_close-vor-fd_read</link><generator>RSS for Node</generator><lastBuildDate>Wed, 01 Jul 2026 18:55:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/190534.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 23 Aug 2007 19:26:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Thu, 23 Aug 2007 19:26:01 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich schreibe an einem Bot, der erst mal nix anderes machen soll, als seiten aus dem Netz runter zu laden. Das klappt auch schon alles ganz gut, nur hab ich jetzt folgendes Problem:<br />
Die Server senden auf meine Anfrage hin jeweils die Daten der ganzen Seite und schließen danach die Verbindung.<br />
Die ankommenden Daten verarbeite ich mit FD_READ und einem relativ kleinen Buffer von 1024 Byte und schreib sie dann in eine Datei.<br />
Jetzt passiert es aber, dass im Event-Handling der WinApi das FD_CLOSE-Event verarbeitet wird, bevor ich es geschafft hab alle Daten zu verarbeiten und da ich in FD_CLOSE die Verbindung schließe gehen mir dann Daten abhanden.</p>
<p>Ich müsste also irgendwie überprüfen können, ob noch FD_READ_Events in der Schleife sind, bevor ich die Verbindung schließe, aber ich hab keine Ahnung wie das gehen kann.</p>
<p>Bitte um Hilfe und Anregungen.</p>
<p>mfg<br />
Ingenuus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1350695</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350695</guid><dc:creator><![CDATA[Ingenuus]]></dc:creator><pubDate>Thu, 23 Aug 2007 19:26:01 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Thu, 23 Aug 2007 20:09:09 GMT]]></title><description><![CDATA[<p>Du musst auf FD_CLOSE *und* FD_READ gleichzeitig warten und dann zuerst pr+fen ob FD_READ gekommen ist!<br />
Siehe: WSAEventSelect, WSAWaitForMultipleEvents, WSAEnumNetworkEvents</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1350717</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350717</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Thu, 23 Aug 2007 20:09:09 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Thu, 23 Aug 2007 20:35:58 GMT]]></title><description><![CDATA[<p>Das Problem ist, dass ich meine Events einfach mit der WinApi nach dem folgendem Shema abfange und verarbeite:</p>
<pre><code>switch (msg) 
      { 
      case WM_SUSCIP:
            switch(WSAGETSELECTEVENT(l))
            {
              case FD_READ:
                   numread = recv(sock,buffer[0],1024,0);
                    fwrite(temp,1,numread,file);

                   break;

              case FD_WRITE:
                   break;

              case FD_CLOSE:
                   fclose(file);
                   WSACleanup();  
              default:
                   break;  
            }
            break;
}
</code></pre>
<p>Da weiß ich nicht wie ich WSAEventSelect, WSAWaitForMultipleEvents, WSAEnumNetworkEvents einbauen soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1350730</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350730</guid><dc:creator><![CDATA[Ingenuus]]></dc:creator><pubDate>Thu, 23 Aug 2007 20:35:58 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Thu, 23 Aug 2007 20:45:00 GMT]]></title><description><![CDATA[<p>Du musst auf jeden Fall um Dein recv noch eine while-Schleife drum rum machen, bis nix mehr empfangen werden kann!<br />
Siehe die Dokzu zu WSASyncSelect:</p>
<blockquote>
<p>The WS2_32.DLL will not continually flood an application with messages for a particular network event. Having successfully posted notification of a particular event to an application window, no further message(s) for that network event will be posted to the application window until the application makes the function call that implicitly reenables notification of that network event.</p>
</blockquote>
<p>D.h. Du musst alles mit recv zuerst auslesen, bevor Du wieder neue Nachrichten annehmen darfst, da sonst vielleicht ein FD_CLOSE kommt und Du noch nicht alle Daten gelesen hast.<br />
Das wird vermutlich schon Dein Problem lösen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1350735</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350735</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Thu, 23 Aug 2007 20:45:00 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Thu, 23 Aug 2007 20:46:34 GMT]]></title><description><![CDATA[<p>PS: Auch solltest Du immer die Rückgabewerte von Funktionen testen!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1350738</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350738</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Thu, 23 Aug 2007 20:46:34 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Thu, 23 Aug 2007 20:54:00 GMT]]></title><description><![CDATA[<p>Nein, auf ein FD_READ Nachricht sollte man nur einmal recv aufrufen.</p>
<blockquote>
<p>With these semantics, an application need not read all available data in response to an FD_READ message — a single recv in response to each FD_READ message is appropriate.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1350742</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350742</guid><dc:creator><![CDATA[.........]]></dc:creator><pubDate>Thu, 23 Aug 2007 20:54:00 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Thu, 23 Aug 2007 20:58:35 GMT]]></title><description><![CDATA[<p>Ähm, WSASyncSelect gibt es bei mir nicht, oder in welchem Paket ist das?</p>
<p>Ich benutzte bereite WSAAsyncSelect, aber das verursacht ja anscheinend das ganze Dilemma.</p>
<p>war das nur ein Tippfehler, oder woher bekomme ich die WSASyncSelect?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1350747</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350747</guid><dc:creator><![CDATA[Ingenuus]]></dc:creator><pubDate>Thu, 23 Aug 2007 20:58:35 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Thu, 23 Aug 2007 21:14:08 GMT]]></title><description><![CDATA[<p>jo, Fipptehler vermutlich <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=";D"
      alt="😉"
    /></p>
<p>Ich quote auch mal:</p>
<p>msdn schrieb:</p>
<blockquote>
<p>FD_CLOSE should only be posted after all data is read from a socket, but an application should check for remaining data upon receipt of FD_CLOSE to avoid any possibility of losing data.</p>
<p>Be aware that the application will only receive an FD_CLOSE message to indicate closure of a virtual circuit, and only when all the received data has been read if this is a graceful close. It will not receive an FD_READ message to indicate this condition.</p>
</blockquote>
<p>Hmm, einfach noch nen recv() vors WSACleanup()? - (Hmm, für gewöhnlich ruft man WSACleanup() erst am Programmende auf und WSAStartup() beim Programmstart? - Hast du nur eine Verbindung?)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1350754</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350754</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Thu, 23 Aug 2007 21:14:08 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Thu, 23 Aug 2007 21:34:18 GMT]]></title><description><![CDATA[<p>hm, gute Idee, aber klappt nicht.</p>
<p>ich rufe WSAStartup() und WSACleanup() jedes mal auf, wenn ich ne neue Verbindung zum Server aufmache und das tu ich für jede seite einzeln.</p>
<p>wenn ich jetzt noch ein recv vor das WSACleanup() hänge bringt das nix, da er damit auch nur einen weiteren Teil der Daten bekommt, aber nicht alles, außerdem schmiert er ab, wenn keine Daten mehr da sein sollten.</p>
<p>ne was ich bräuchte wäre ne möglichkeit, die FD_CLOSE solange auszubremsen, bis wirklich alle FD_READ weg sind.</p>
<p>Ich wollte eigendlich schon mein WSAAsyncSelect() bebehalten, weil ich das ganz elegant find, aber wenn alles nix Hilft muss ich halt nochmal den ganzen Code umstellen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1350761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350761</guid><dc:creator><![CDATA[Ingenuus]]></dc:creator><pubDate>Thu, 23 Aug 2007 21:34:18 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Fri, 24 Aug 2007 06:16:01 GMT]]></title><description><![CDATA[<p>......... schrieb:</p>
<blockquote>
<p>Nein, auf ein FD_READ Nachricht sollte man nur einmal recv aufrufen.</p>
<blockquote>
<p>With these semantics, an application need not read all available data in response to an FD_READ message — a single recv in response to each FD_READ message is appropriate.</p>
</blockquote>
</blockquote>
<p>Wenn aber anschliessend ein FD_CLOSE kommt, dann hast Du ein Problem...<br />
Das Hauptproblem ist aber: Wenn Du ein recv mit Buffergröse von 1024 aufrufst und 2000 Bytes angekommen sind, so bleibt ein Teil übrig... dieser Teil kann schlimmstenfalls immer größer werden u´nd wird von Dir dann nich abgeholt.</p>
<p>Ich kann nur dazu raten das recv so oft aufzurufen, bis weniger zurückkommt als der Buffer gross ist.</p>
<p>Es steht ja auch nicht da, dass es nicht erlaubt ist... ich mache es bei mir immer und es funktioniert tadelos...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1350845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350845</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Fri, 24 Aug 2007 06:16:01 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Fri, 24 Aug 2007 06:00:20 GMT]]></title><description><![CDATA[<p>Wie gesagt: Du <strong>musst</strong> auf FD_READ, das recv so oft in einer Schleife aufrufen, bis weniger zurückkommt, als der Bufer gross ist! Dann geht alles!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1350848</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350848</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Fri, 24 Aug 2007 06:00:20 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Fri, 24 Aug 2007 09:42:34 GMT]]></title><description><![CDATA[<p>Das ist nicht nötig, wenn noch Daten da sind wird wieder eine FD_READ Nachricht generiert. Und genau deshalb sollte man es nur einmal aufrufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1351001</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1351001</guid><dc:creator><![CDATA[.........]]></dc:creator><pubDate>Fri, 24 Aug 2007 09:42:34 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Fri, 24 Aug 2007 11:44:14 GMT]]></title><description><![CDATA[<p>Ich habs jetzt mit der Holzhammermethode gelöst:</p>
<p>WSAAsyncSelect rausgenommen und ne einfache Schleife um recv gelegt.</p>
<p>Is zwar nicht elegant, funktioniert aber und scheint für meinen Zweck vollkommen ausreichend zu sein.</p>
<p>Danke nochmal für die Anregungen.</p>
<p>Wenn ich den Code posten soll sagt bescheid.</p>
<p>mfg<br />
Ingenuus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1351088</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1351088</guid><dc:creator><![CDATA[Ingenuus]]></dc:creator><pubDate>Fri, 24 Aug 2007 11:44:14 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Fri, 24 Aug 2007 11:50:07 GMT]]></title><description><![CDATA[<p>Jochen Kalmbach schrieb:</p>
<blockquote>
<p>Wie gesagt: Du <strong>musst</strong> auf FD_READ, das recv so oft in einer Schleife aufrufen, bis weniger zurückkommt, als der Bufer gross ist! Dann geht alles!</p>
</blockquote>
<p>Laut msdn ist FD_READ da eine Ausnahme: Sobald recv() einmal aufgerufen wurde wird sofort im Anschluss geprüft ob immer noch was im Buffer ist und FD_READ erneut gesendet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1351092</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1351092</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Fri, 24 Aug 2007 11:50:07 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Fri, 24 Aug 2007 16:55:35 GMT]]></title><description><![CDATA[<p>Habs nicht probiert... mag sein... schaden tut meine Implementierung auf jeden Fall auch nicht und baut nicht auf vermutungen die ich so nicht direkt eindeutig in der Doku lesen kann... oder wo steht es direkt eindeutig?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1351346</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1351346</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Fri, 24 Aug 2007 16:55:35 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Fri, 24 Aug 2007 18:00:56 GMT]]></title><description><![CDATA[<p>...steht ein bisschen weiter unten:</p>
<p>msdn schrieb:</p>
<blockquote>
<p>Any call to the reenabling routine, even one that fails, results in reenabling of message posting for the relevant event.</p>
<p>For FD_READ, FD_OOB, and FD_ACCEPT events, message posting is level-triggered. This means that if the reenabling routine is called and the relevant condition is still met after the call, a WSAAsyncSelect message is posted to the application. This allows an application to be event-driven and not be concerned with the amount of data that arrives at any one time. Consider the following sequence:<br />
- Network transport stack receives 100 bytes of data on socket s and causes Windows Sockets 2 to post an FD_READ message.<br />
- The application issues recv( s, buffptr, 50, 0) to read 50 bytes.<br />
- Another FD_READ message is posted because there is still data to be read.</p>
<p>With these semantics, an application need not read all available data in response to an FD_READ message — a single recv in response to each FD_READ message is appropriate.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1351375</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1351375</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Fri, 24 Aug 2007 18:00:56 GMT</pubDate></item><item><title><![CDATA[Reply to FD_CLOSE vor FD_READ on Fri, 24 Aug 2007 19:20:37 GMT]]></title><description><![CDATA[<p>Super vielen Dank! Hab ich jetzt auch so nicht gewusst...<br />
Danke für das Quoten (bin gerade im Urlaub und kann nicht so viel MSDN lesen <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/1351424</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1351424</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Fri, 24 Aug 2007 19:20:37 GMT</pubDate></item></channel></rss>