<?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[unerklaerlicher doppelter aufruf einer funktion]]></title><description><![CDATA[<p>hola leute</p>
<p>hab mir eine socketklasse fuer einen tcp-server geschrieben.<br />
fuer benachrichtigungen verschiedenster art hab ich bcb-events hinzugefuegt.<br />
nun hab ich das problem das meine funktion 'on_close' doppelt aufgerufen wird.<br />
mal bissl code:</p>
<pre><code class="language-cpp">class Socket
{
   public:
      Socket(void);
      Socket(const Socket &amp;s);
      virtual ~Socket(void);

      SOCKET GetSocket(void) const;
      operator SOCKET(void) const;
      virtual void CloseSocket(void)
      {
         if(socket)
         {
            ::closesocket(socket);
            socket = 0;
         }
      }  

   protected:
      SOCKET socket;
};

template&lt;int family, int socktype, int protocol&gt;
class ServerSocket : public Socket
{
   public:
      ServerSocket(void) : port(0) { }
      ServerSocket(const ServerSocket &amp;ss) : Socket(ss), port(ss.port) { }
      virtual ~ServerSocket(void) { }

      bool BindSocket(unsigned short t_port);

      virtual void CloseSocket(void)
      {
         Socket::CloseSocket();
         port = 0;
      }

      bool IsActive(void) const;
      unsigned short GetPort(void) const;
};

class TcpServer : public ServerSocket&lt;AF_INET, SOCK_STREAM, IPPROTO_TCP&gt;
{
   public:
      typedef void (__closure *OnListen)(SOCKET socket);
      typedef void (__closure *OnAccept)(SOCKET socket);
      typedef void (__closure *OnClose)(SOCKET socket);
      typedef void (__closure *OnConnected)(TcpServer *server, SOCKET client);
      typedef void (__closure *OnError)(TcpServer *server, const char *str);
      typedef void (__closure *OnStatus)(TcpServer *server, const char *str);

      TcpServer(void);
      TcpServer(const TcpServer &amp;ts);
      virtual ~TcpServer(void);

      bool Listen(void);
      virtual void CloseSocket(void);

      OnListen on_listen;
      OnAccept on_accept;
      OnClose on_close;
      OnConnected on_connected;
      OnError on_error;
      OnStatus on_status;
};

// cpp-file
void TcpServer::CloseSocket(void)
{
   if(on_close)
      on_close(socket);

   ServerSocket&lt;AF_INET, SOCK_STREAM, IPPROTO_TCP&gt;::CloseSocket();  //(1)
}
</code></pre>
<p>wenn ich nun CloseSocket aufrufe, wird on_close 2x aufgerufen.<br />
wenn ich zeile (1) wegtue wird on_close nur noch einmal aufgerufen.<br />
sieht da jemand den fehler ?</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/196576/unerklaerlicher-doppelter-aufruf-einer-funktion</link><generator>RSS for Node</generator><lastBuildDate>Wed, 30 Sep 2026 14:15:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/196576.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 31 Oct 2007 13:13:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to unerklaerlicher doppelter aufruf einer funktion on Wed, 31 Oct 2007 13:13:55 GMT]]></title><description><![CDATA[<p>hola leute</p>
<p>hab mir eine socketklasse fuer einen tcp-server geschrieben.<br />
fuer benachrichtigungen verschiedenster art hab ich bcb-events hinzugefuegt.<br />
nun hab ich das problem das meine funktion 'on_close' doppelt aufgerufen wird.<br />
mal bissl code:</p>
<pre><code class="language-cpp">class Socket
{
   public:
      Socket(void);
      Socket(const Socket &amp;s);
      virtual ~Socket(void);

      SOCKET GetSocket(void) const;
      operator SOCKET(void) const;
      virtual void CloseSocket(void)
      {
         if(socket)
         {
            ::closesocket(socket);
            socket = 0;
         }
      }  

   protected:
      SOCKET socket;
};

template&lt;int family, int socktype, int protocol&gt;
class ServerSocket : public Socket
{
   public:
      ServerSocket(void) : port(0) { }
      ServerSocket(const ServerSocket &amp;ss) : Socket(ss), port(ss.port) { }
      virtual ~ServerSocket(void) { }

      bool BindSocket(unsigned short t_port);

      virtual void CloseSocket(void)
      {
         Socket::CloseSocket();
         port = 0;
      }

      bool IsActive(void) const;
      unsigned short GetPort(void) const;
};

class TcpServer : public ServerSocket&lt;AF_INET, SOCK_STREAM, IPPROTO_TCP&gt;
{
   public:
      typedef void (__closure *OnListen)(SOCKET socket);
      typedef void (__closure *OnAccept)(SOCKET socket);
      typedef void (__closure *OnClose)(SOCKET socket);
      typedef void (__closure *OnConnected)(TcpServer *server, SOCKET client);
      typedef void (__closure *OnError)(TcpServer *server, const char *str);
      typedef void (__closure *OnStatus)(TcpServer *server, const char *str);

      TcpServer(void);
      TcpServer(const TcpServer &amp;ts);
      virtual ~TcpServer(void);

      bool Listen(void);
      virtual void CloseSocket(void);

      OnListen on_listen;
      OnAccept on_accept;
      OnClose on_close;
      OnConnected on_connected;
      OnError on_error;
      OnStatus on_status;
};

// cpp-file
void TcpServer::CloseSocket(void)
{
   if(on_close)
      on_close(socket);

   ServerSocket&lt;AF_INET, SOCK_STREAM, IPPROTO_TCP&gt;::CloseSocket();  //(1)
}
</code></pre>
<p>wenn ich nun CloseSocket aufrufe, wird on_close 2x aufgerufen.<br />
wenn ich zeile (1) wegtue wird on_close nur noch einmal aufgerufen.<br />
sieht da jemand den fehler ?</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1395209</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395209</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Wed, 31 Oct 2007 13:13:55 GMT</pubDate></item><item><title><![CDATA[Reply to unerklaerlicher doppelter aufruf einer funktion on Wed, 31 Oct 2007 13:35:49 GMT]]></title><description><![CDATA[<p>Hast du mal im Debugger verfolgt, von wo aus die Funktion aufgerufen wird? (Call-Stacks sind da eine durchaus nützliche Erfindung)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1395226</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395226</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 31 Oct 2007 13:35:49 GMT</pubDate></item><item><title><![CDATA[Reply to unerklaerlicher doppelter aufruf einer funktion on Wed, 31 Oct 2007 13:53:33 GMT]]></title><description><![CDATA[<p>re<br />
fehler gefunden. hab an ner anderen stelle anstatt den clientsocket, den server socket nochmal geschlossen.</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1395238</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395238</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Wed, 31 Oct 2007 13:53:33 GMT</pubDate></item></channel></rss>