<?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[Netzwerk: select mit 2 Descriptoren ( socket und stdin )]]></title><description><![CDATA[<p>Liebe Gemeinde,</p>
<p>ich habe mir ein Bsp. aus dem Buch &quot;Unix Netzwerkprogrammierung&quot; genommen,<br />
arbeite aber mal auf Windows ab <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Die Forensuche ergab ein nahezu passendes Thema vom 4 Mai 2004 wobei<br />
es jedoch um Socket und Pipe im SET was auf select angewendet wird ging.<br />
Eine Lösung war aber nicht so recht erkennbar.</p>
<pre><code class="language-cpp">void str_cli(FILE* fp, int sockfd)
{
	int maxfdp1;
	fd_set	rset;
	DWORD dwErr;

	char sendline[1024]={0}, recvline[1024]={0};

	FD_ZERO(&amp;rset);

	while( 1 )
	{
		FD_SET(fileno(fp), &amp;rset);
		FD_SET(sockfd, &amp;rset);
		maxfdp1 = max((unsigned)fileno(fp), (unsigned)sockfd) + 1;

		select(maxfdp1, &amp;rset, NULL, NULL, NULL);

		dwErr = WSAGetLastError();

		if( FD_ISSET(sockfd, &amp;rset) )
		{
			if( socket_readlinefast(sockfd, recvline, 1023) == 0 )
			{
				printf(&quot;server terminated prematurely\n&quot;);
				return ;
			}
			fputs(recvline, stdout);
		}
		if( FD_ISSET(fileno(fp), &amp;rset) )
		{
			if( fgets(sendline, 1023, fp) == NULL )
				return;

			socket_write(sockfd, sendline, strlen(sendline));
		}
	}

}
</code></pre>
<p>die Funktion wird mit<br />
str_cli(stdin, sockfd);<br />
aufgerufen.</p>
<p>dwErr nach select liefert 10038 - Vorgang bezog sich auf ein Objekt was kein Socket ist.</p>
<p>Alles klar.</p>
<p>Ohne stdin in das SET mit aufzunehmen &quot;funktioniert&quot; es, heißt select blockiert.</p>
<p>Frage ist ob select unter Windows mit stdin überhaupt klar kommt ...</p>
<p>Vielen Dank.<br />
Schönes WE und mfg</p>
<p>RB</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/106447/netzwerk-select-mit-2-descriptoren-socket-und-stdin</link><generator>RSS for Node</generator><lastBuildDate>Mon, 29 Jun 2026 21:24:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/106447.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 10 Apr 2005 08:58:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Netzwerk: select mit 2 Descriptoren ( socket und stdin ) on Sun, 10 Apr 2005 08:58:24 GMT]]></title><description><![CDATA[<p>Liebe Gemeinde,</p>
<p>ich habe mir ein Bsp. aus dem Buch &quot;Unix Netzwerkprogrammierung&quot; genommen,<br />
arbeite aber mal auf Windows ab <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Die Forensuche ergab ein nahezu passendes Thema vom 4 Mai 2004 wobei<br />
es jedoch um Socket und Pipe im SET was auf select angewendet wird ging.<br />
Eine Lösung war aber nicht so recht erkennbar.</p>
<pre><code class="language-cpp">void str_cli(FILE* fp, int sockfd)
{
	int maxfdp1;
	fd_set	rset;
	DWORD dwErr;

	char sendline[1024]={0}, recvline[1024]={0};

	FD_ZERO(&amp;rset);

	while( 1 )
	{
		FD_SET(fileno(fp), &amp;rset);
		FD_SET(sockfd, &amp;rset);
		maxfdp1 = max((unsigned)fileno(fp), (unsigned)sockfd) + 1;

		select(maxfdp1, &amp;rset, NULL, NULL, NULL);

		dwErr = WSAGetLastError();

		if( FD_ISSET(sockfd, &amp;rset) )
		{
			if( socket_readlinefast(sockfd, recvline, 1023) == 0 )
			{
				printf(&quot;server terminated prematurely\n&quot;);
				return ;
			}
			fputs(recvline, stdout);
		}
		if( FD_ISSET(fileno(fp), &amp;rset) )
		{
			if( fgets(sendline, 1023, fp) == NULL )
				return;

			socket_write(sockfd, sendline, strlen(sendline));
		}
	}

}
</code></pre>
<p>die Funktion wird mit<br />
str_cli(stdin, sockfd);<br />
aufgerufen.</p>
<p>dwErr nach select liefert 10038 - Vorgang bezog sich auf ein Objekt was kein Socket ist.</p>
<p>Alles klar.</p>
<p>Ohne stdin in das SET mit aufzunehmen &quot;funktioniert&quot; es, heißt select blockiert.</p>
<p>Frage ist ob select unter Windows mit stdin überhaupt klar kommt ...</p>
<p>Vielen Dank.<br />
Schönes WE und mfg</p>
<p>RB</p>
]]></description><link>https://www.c-plusplus.net/forum/post/763352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/763352</guid><dc:creator><![CDATA[RED-BARON]]></dc:creator><pubDate>Sun, 10 Apr 2005 08:58:24 GMT</pubDate></item></channel></rss>