<?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[SIGSEGV verursacht durch aufruf von FD_SET]]></title><description><![CDATA[<p>Hallo in die Runde.<br />
Ich habe wiedermal ein Problem bei dem ich eure Hilfe brauche.<br />
Wie in der überschrift bereits erwähnt wird bei meinem Programm ein SIGSEGV signal empfangen und daruafhin natürlich abgebrochen. Ich kann mir nicht erklären wo dieser Fehler herkommt.</p>
<p>1. Fehlermeldung erzeugt von gdb:</p>
<pre><code>Program received signal SIGSEGV, Segmentation fault.
0x08051c92 in socketx::confSelect (this=0x805fbd0, sec=5, usec=0)
    at socketx.cpp:20
20		FD_SET(sock, &amp;fds);
(gdb) where
#0  0x08051c92 in socketx::confSelect (this=0x805fbd0, sec=5, usec=0)
    at socketx.cpp:20
#1  0x080522f7 in socketx::TCP_send (this=0x805fbd0, obuf=0xbfffebec &quot;&quot;, 
    byteCount=12) at socketx.cpp:118
#2  0x0804f490 in devRead::readValue (this=0xbfffebd4, valueInterprete=..., 
    regNo=1, startReg=2, sockNr=1) at devRead.cpp:67
#3  0x08053186 in main (argc=1, argv=0xbffff394) at watchDog.cpp:164
</code></pre>
<p>2. Code (angeblicher verursacher in File socketx.cpp line 20)</p>
<pre><code>void socketx::confSelect(int sec, int usec){
	FD_ZERO(&amp;fds);
	FD_SET(sock, &amp;fds);     // !!Hier tritt angeblich der fehler auf!!!
	tv.tv_sec = sec;
	tv.tv_usec = usec;	// timeout fÃ¼r select nach 500 microsekunden
}
</code></pre>
<p>Die aufrufende Fkt. (aus der selben klasse)</p>
<pre><code>int socketx::TCP_send(char* obuf, int byteCount){//gibt anzahl der gesendeten bytes zurÃ¼ck

	this-&gt;confSelect(5, 0);//fdset und timeout setzen
	sockRValue = select(sock+1, NULL, &amp;fds, NULL, &amp;tv);
	if (sockRValue &lt;= 0){
		throw SockExcept(&quot;[socket:TCP_send] Server Antwortet nicht (evtl netzwerk problem, timeout)&quot;,1016);
	}
	sockRValue = send(sock, obuf, byteCount, 0);

	if (sockRValue == -1){
		throw SockExcept(&quot;[socket::TCP_send] Fehler beim Senden der Daten&quot;,1011);
	}

	return sockRValue;
}
</code></pre>
<p>3. Das dazugehörige headerfile:</p>
<pre><code>#ifndef SOCKETX_H_
#define SOCKETX_H_

#include &lt;string&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;netdb.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;unistd.h&gt;
#include &lt;sstream&gt;
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;errno.h&gt;

using namespace std;

class socketx{

public:

	socketx();	// Konstruktor
	int init(string ipAdress, int port);
	int TCP_send(char* obuf, int byteCount);
	int TCP_recv(unsigned char* ibuf, int byteCount);

private:

	int sock;				//id des sockets
	int error;				// Vaiabel um error auf zu nehmen
	int sockRValue;
	struct hostent *ip_adrs;
	struct sockaddr_in server_addr;
	const char *adresse;
	unsigned long ip;
	fd_set fds;
	struct timeval tv;
	void confSelect(int sec, int usec);

};

class SockExcept{
	private:
		string except;
		int eno;
	public:
		SockExcept(string s, int eno) : except(s) {this-&gt;eno= eno;}
		~SockExcept(){}
		string get_SockExcept(int &amp;eno) {eno=this-&gt;eno; return except;}

};

#endif /* SOCKETX_H_ */
</code></pre>
<p>Ich hoffe ihr könnt mir wie immer Helfen.<br />
Mfg BabCom</p>
<p>PS: Danke schon mal vorab ^^^^</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/320371/sigsegv-verursacht-durch-aufruf-von-fd_set</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Jul 2026 02:40:32 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/320371.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 25 Sep 2013 16:10:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SIGSEGV verursacht durch aufruf von FD_SET on Wed, 25 Sep 2013 16:10:22 GMT]]></title><description><![CDATA[<p>Hallo in die Runde.<br />
Ich habe wiedermal ein Problem bei dem ich eure Hilfe brauche.<br />
Wie in der überschrift bereits erwähnt wird bei meinem Programm ein SIGSEGV signal empfangen und daruafhin natürlich abgebrochen. Ich kann mir nicht erklären wo dieser Fehler herkommt.</p>
<p>1. Fehlermeldung erzeugt von gdb:</p>
<pre><code>Program received signal SIGSEGV, Segmentation fault.
0x08051c92 in socketx::confSelect (this=0x805fbd0, sec=5, usec=0)
    at socketx.cpp:20
20		FD_SET(sock, &amp;fds);
(gdb) where
#0  0x08051c92 in socketx::confSelect (this=0x805fbd0, sec=5, usec=0)
    at socketx.cpp:20
#1  0x080522f7 in socketx::TCP_send (this=0x805fbd0, obuf=0xbfffebec &quot;&quot;, 
    byteCount=12) at socketx.cpp:118
#2  0x0804f490 in devRead::readValue (this=0xbfffebd4, valueInterprete=..., 
    regNo=1, startReg=2, sockNr=1) at devRead.cpp:67
#3  0x08053186 in main (argc=1, argv=0xbffff394) at watchDog.cpp:164
</code></pre>
<p>2. Code (angeblicher verursacher in File socketx.cpp line 20)</p>
<pre><code>void socketx::confSelect(int sec, int usec){
	FD_ZERO(&amp;fds);
	FD_SET(sock, &amp;fds);     // !!Hier tritt angeblich der fehler auf!!!
	tv.tv_sec = sec;
	tv.tv_usec = usec;	// timeout fÃ¼r select nach 500 microsekunden
}
</code></pre>
<p>Die aufrufende Fkt. (aus der selben klasse)</p>
<pre><code>int socketx::TCP_send(char* obuf, int byteCount){//gibt anzahl der gesendeten bytes zurÃ¼ck

	this-&gt;confSelect(5, 0);//fdset und timeout setzen
	sockRValue = select(sock+1, NULL, &amp;fds, NULL, &amp;tv);
	if (sockRValue &lt;= 0){
		throw SockExcept(&quot;[socket:TCP_send] Server Antwortet nicht (evtl netzwerk problem, timeout)&quot;,1016);
	}
	sockRValue = send(sock, obuf, byteCount, 0);

	if (sockRValue == -1){
		throw SockExcept(&quot;[socket::TCP_send] Fehler beim Senden der Daten&quot;,1011);
	}

	return sockRValue;
}
</code></pre>
<p>3. Das dazugehörige headerfile:</p>
<pre><code>#ifndef SOCKETX_H_
#define SOCKETX_H_

#include &lt;string&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;netdb.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;unistd.h&gt;
#include &lt;sstream&gt;
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;errno.h&gt;

using namespace std;

class socketx{

public:

	socketx();	// Konstruktor
	int init(string ipAdress, int port);
	int TCP_send(char* obuf, int byteCount);
	int TCP_recv(unsigned char* ibuf, int byteCount);

private:

	int sock;				//id des sockets
	int error;				// Vaiabel um error auf zu nehmen
	int sockRValue;
	struct hostent *ip_adrs;
	struct sockaddr_in server_addr;
	const char *adresse;
	unsigned long ip;
	fd_set fds;
	struct timeval tv;
	void confSelect(int sec, int usec);

};

class SockExcept{
	private:
		string except;
		int eno;
	public:
		SockExcept(string s, int eno) : except(s) {this-&gt;eno= eno;}
		~SockExcept(){}
		string get_SockExcept(int &amp;eno) {eno=this-&gt;eno; return except;}

};

#endif /* SOCKETX_H_ */
</code></pre>
<p>Ich hoffe ihr könnt mir wie immer Helfen.<br />
Mfg BabCom</p>
<p>PS: Danke schon mal vorab ^^^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2355526</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2355526</guid><dc:creator><![CDATA[BabCom]]></dc:creator><pubDate>Wed, 25 Sep 2013 16:10:22 GMT</pubDate></item><item><title><![CDATA[Reply to SIGSEGV verursacht durch aufruf von FD_SET on Wed, 25 Sep 2013 16:47:44 GMT]]></title><description><![CDATA[<p>Weißt du, ob <code>this</code> gültig ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2355536</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2355536</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 25 Sep 2013 16:47:44 GMT</pubDate></item><item><title><![CDATA[Reply to SIGSEGV verursacht durch aufruf von FD_SET on Thu, 26 Sep 2013 08:45:21 GMT]]></title><description><![CDATA[<p>Überdenke mal die Klasse. Was mir so spontan auffällt:</p>
<ul>
<li>nie <code>using namespace</code> im Header!</li>
<li><code>#include</code> am besten alles, da alles viel hilft? <code>&lt;sstream&gt;</code> , <code>&lt;iostream&gt;</code> sind beispielsweise überflüssig.</li>
<li>Exception Klasse nicht von <code>std::exception</code> abgeleitet</li>
<li>Ich bezweifle, dass alle Membervariablen wirklich notwendig sind, um den Zustand eines Sockets zu halten. In der Regel reicht der Filedeskriptor.</li>
<li><code>TCP_send</code> erwartet einen nicht konstanten Zeiger. Was will denn TCP_send da rein schreiben?</li>
<li><code>TCP_send</code> arbeitet mit <code>char*</code> , <code>TCP_recv</code> aber mit <code>unsigned char*</code> .</li>
<li>Zeiger als member ( <code>addresse</code> , <code>ip_adrs</code> ) verlangen in der Regel nach einem Kopierkonstruktor und Zuweisungsoperator.</li>
</ul>
<p>Das das Programm bei dem Programmierstil abstürzt wundert mich nicht wirklich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2355646</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2355646</guid><dc:creator><![CDATA[tntnet]]></dc:creator><pubDate>Thu, 26 Sep 2013 08:45:21 GMT</pubDate></item><item><title><![CDATA[Reply to SIGSEGV verursacht durch aufruf von FD_SET on Wed, 02 Oct 2013 13:06:59 GMT]]></title><description><![CDATA[<p>HI, danke für die Antworten.<br />
Also Wenn ich das namespace std; aus der hederdatei(en) entferne, bekomme ich in fast allen Klassen Probleme mit den membervariablen bzw. den übergabeparametern.<br />
(string, stringstream, vektor etc. werden nicht mehr erkannt). Wenn ich das also nicht so machen darf/soll wie soll ich das dann machen?</p>
<p>sstream und iostream haste auc hrecht sind hier überflüssig geworden hatten in dem ursprünglichem entwurf aber durch aus ihren sinn. (Rausgenommen)</p>
<p>TCPsend, da haste recht das als Zeiger zu übergeben ist eigentlich quatsch. werde ich ändern.</p>
<p>TCP Recv ist so richtig(denke ich), da der ModbusTCP Master mit einem unsigned char array antwortet, welches dann byte weise ausgewertet werden muss.<br />
(richtige Antwort, Error, etc.).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2357309</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2357309</guid><dc:creator><![CDATA[BabCom]]></dc:creator><pubDate>Wed, 02 Oct 2013 13:06:59 GMT</pubDate></item><item><title><![CDATA[Reply to SIGSEGV verursacht durch aufruf von FD_SET on Wed, 02 Oct 2013 13:30:38 GMT]]></title><description><![CDATA[<p>das ich die Exeption nicht von std::exeption abgeleitet habe hatt den grund, dass mir da eine eigene (sehr abgespeckte) klasse gebaut habe, welche den selben mechanismus benutzt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2357312</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2357312</guid><dc:creator><![CDATA[BabCom]]></dc:creator><pubDate>Wed, 02 Oct 2013 13:30:38 GMT</pubDate></item><item><title><![CDATA[Reply to SIGSEGV verursacht durch aufruf von FD_SET on Wed, 02 Oct 2013 13:17:18 GMT]]></title><description><![CDATA[<p>BabCom schrieb:</p>
<blockquote>
<p>HI, danke für die Antworten.<br />
Also Wenn ich das namespace std; aus der hederdatei(en) entferne, bekomme ich in fast allen Klassen Probleme mit den membervariablen bzw. den übergabeparametern.<br />
(string, stringstream, vektor etc. werden nicht mehr erkannt). Wenn ich das also nicht so machen darf/soll wie soll ich das dann machen?</p>
</blockquote>
<p>Explizite Qualifikation natürlich. std::string usw.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2357316</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2357316</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Wed, 02 Oct 2013 13:17:18 GMT</pubDate></item><item><title><![CDATA[Reply to SIGSEGV verursacht durch aufruf von FD_SET on Wed, 02 Oct 2013 13:24:30 GMT]]></title><description><![CDATA[<p>ah klar^^ danke,<br />
werde ich umgehend ändern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2357320</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2357320</guid><dc:creator><![CDATA[BabCom]]></dc:creator><pubDate>Wed, 02 Oct 2013 13:24:30 GMT</pubDate></item><item><title><![CDATA[Reply to SIGSEGV verursacht durch aufruf von FD_SET on Wed, 02 Oct 2013 14:08:15 GMT]]></title><description><![CDATA[<p>Hatt den noch jemand eine idee was diesen Fehler auslösen könnte? ich binn natürlich auch für weitere formale verbesserungen offen ^^.<br />
Mfg BabCom</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2357345</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2357345</guid><dc:creator><![CDATA[BabCom]]></dc:creator><pubDate>Wed, 02 Oct 2013 14:08:15 GMT</pubDate></item><item><title><![CDATA[Reply to SIGSEGV verursacht durch aufruf von FD_SET on Wed, 02 Oct 2013 14:34:42 GMT]]></title><description><![CDATA[<p>BabCom schrieb:</p>
<blockquote>
<p>Also Wenn ich das namespace std; aus der hederdatei(en) entferne, bekomme ich in fast allen Klassen Probleme mit den membervariablen bzw. den übergabeparametern.<br />
(string, stringstream, vektor etc. werden nicht mehr erkannt). Wenn ich das also nicht so machen darf/soll wie soll ich das dann machen?</p>
</blockquote>
<p>aufgrund dieser aussage vermute ich, dass der code nicht vom te selbst geschrieben / verstanden wurde.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2357357</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2357357</guid><dc:creator><![CDATA[kenner der unwissenden]]></dc:creator><pubDate>Wed, 02 Oct 2013 14:34:42 GMT</pubDate></item><item><title><![CDATA[Reply to SIGSEGV verursacht durch aufruf von FD_SET on Wed, 02 Oct 2013 14:42:41 GMT]]></title><description><![CDATA[<p>BabCom schrieb:</p>
<blockquote>
<p>Hatt den noch jemand eine idee was diesen Fehler auslösen könnte?</p>
</blockquote>
<p>Nimm doch mal zu Sones Frage Stellung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2357361</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2357361</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Wed, 02 Oct 2013 14:42:41 GMT</pubDate></item><item><title><![CDATA[Reply to SIGSEGV verursacht durch aufruf von FD_SET on Wed, 02 Oct 2013 16:45:26 GMT]]></title><description><![CDATA[<p>tja also ich habe den Fehler im endefekt gefunden.</p>
<p>Problem wahr, das ich in einer anderen Klasse bestimme wieviele Sockets angelegt werden müssen oben bennante klasse veranlasst mittels der init Fkt einen anzulegen . dabei habe ich mir einen kleinen Fehler geleistet (hatte an einer stelle ein +1 drinne weshalb 1 socket zuviel angelegt wurde), dies wiederum führte dazu das versucht wurde auf einen socket zuschreiben welcher nicht existiert daher der fehler.</p>
<p>@Sones: ja der this-&gt; zeiger ist gülltig.</p>
<p>Danke für eure Hilfe. Auch wenn ihr den fFhler garnicht finden konntet ^^ so habt ihr mir doch bei einigen vormalen dingen helfen können.</p>
<p>MfG BabCom</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2357382</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2357382</guid><dc:creator><![CDATA[BabCom]]></dc:creator><pubDate>Wed, 02 Oct 2013 16:45:26 GMT</pubDate></item></channel></rss>