Browse Source

Prüfung ob SSL server noch aktiv ist eingebaut

Kolja Strohm 6 years ago
parent
commit
a09e6ffb6c
2 changed files with 25 additions and 1 deletions
  1. 22 0
      Network/Server.cpp
  2. 3 1
      Network/Server.h

+ 22 - 0
Network/Server.cpp

@@ -339,11 +339,20 @@ bool SSLServer::verbinde( unsigned short port, int warteschlangenLen )
     addr.sin_port = htons( port );
     addr.sin_port = htons( port );
     s = socket( AF_INET, SOCK_STREAM, 0 );
     s = socket( AF_INET, SOCK_STREAM, 0 );
     if( s < 0 )
     if( s < 0 )
+    {
+        s = 0;
         return 0;
         return 0;
+    }
     if( bind( s, ( struct sockaddr* )&addr, sizeof( addr ) ) < 0 )
     if( bind( s, ( struct sockaddr* )&addr, sizeof( addr ) ) < 0 )
+    {
+        trenne();
         return 0;
         return 0;
+    }
     if( listen( s, warteschlangenLen ) < 0 )
     if( listen( s, warteschlangenLen ) < 0 )
+    {
+        trenne();
         return 0;
         return 0;
+    }
     return 1;
     return 1;
 }
 }
 
 
@@ -357,11 +366,18 @@ SSLSKlient *SSLServer::getKlient()
 #ifdef WIN32
 #ifdef WIN32
     SOCKET client = accept( s, ( struct sockaddr* )&addr, &len );
     SOCKET client = accept( s, ( struct sockaddr* )&addr, &len );
     if( client == INVALID_SOCKET )
     if( client == INVALID_SOCKET )
+    {
+        trenne();
         return 0;
         return 0;
+    }
 #else
 #else
     SOCKET client = accept( s, (sockaddr*)&addr, (socklen_t*)&len ); // Klient empfangen
     SOCKET client = accept( s, (sockaddr*)&addr, (socklen_t*)&len ); // Klient empfangen
     if( !client )
     if( !client )
+    {
+        if( errno == ECONNABORTED || errno == EBADF )
+            trenne();
         return 0;
         return 0;
+    }
 #endif
 #endif
     addr.sin_port = this->addr.sin_port;
     addr.sin_port = this->addr.sin_port;
     SSL *ssl = SSL_new( ctx );
     SSL *ssl = SSL_new( ctx );
@@ -403,6 +419,12 @@ unsigned short SSLServer::getPort() const
     return htons( addr.sin_port );
     return htons( addr.sin_port );
 }
 }
 
 
+// giebt 1 zurück, falls der Server verbunden ist
+bool SSLServer::isConnected() const
+{
+    return s != 0;
+}
+
 // Reference Counting 
 // Reference Counting 
 SSLServer *SSLServer::getThis()
 SSLServer *SSLServer::getThis()
 {
 {

+ 3 - 1
Network/Server.h

@@ -119,7 +119,9 @@ namespace Network
         __declspec( dllexport ) bool trenne();
         __declspec( dllexport ) bool trenne();
         // constant
         // constant
         // gibt den Port zurück
         // gibt den Port zurück
-        __declspec( dllexport ) unsigned short getPort() const; 
+        __declspec( dllexport ) unsigned short getPort() const;
+        // giebt 1 zurück, falls der Server verbunden ist
+        __declspec( dllexport ) bool isConnected() const;
         // Reference Counting 
         // Reference Counting 
         __declspec( dllexport ) SSLServer *getThis();
         __declspec( dllexport ) SSLServer *getThis();
         __declspec( dllexport ) SSLServer *release();
         __declspec( dllexport ) SSLServer *release();