|
@@ -32,9 +32,15 @@ bool Server::verbinde( unsigned short port, int warteschlangenLen ) //
|
|
|
sock = socket( AF_INET, SOCK_STREAM, 0 ); // Socket erstellen
|
|
|
addresse.sin_port = htons( port ); // port setzen
|
|
|
if( bind( sock, ( struct sockaddr* )&addresse, sizeof( addresse ) ) == -1 ) // socket öffnen
|
|
|
+ {
|
|
|
+ trenne();
|
|
|
return 0; // Fehler
|
|
|
+ }
|
|
|
if( listen( sock, warteschlangenLen ) == -1 ) // Klients annehmen
|
|
|
+ {
|
|
|
+ trenne();
|
|
|
return 0; // Fehler
|
|
|
+ }
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
@@ -47,11 +53,18 @@ SKlient *Server::getKlient() // nimmt Klient an
|
|
|
#ifdef WIN32
|
|
|
SOCKET cls = accept( sock, (sockaddr*)&client, &len ); // Klient empfangen
|
|
|
if( cls == INVALID_SOCKET )
|
|
|
+ {
|
|
|
+ trenne();
|
|
|
return 0;
|
|
|
+ }
|
|
|
#else
|
|
|
SOCKET cls = accept( sock, (sockaddr*)&client, (socklen_t*)&len ); // Klient empfangen
|
|
|
if( !cls )
|
|
|
+ {
|
|
|
+ if( errno == ECONNABORTED || errno == EBADF )
|
|
|
+ trenne();
|
|
|
return 0;
|
|
|
+ }
|
|
|
#endif
|
|
|
client.sin_port = addresse.sin_port;
|
|
|
klients++;
|
|
@@ -82,6 +95,11 @@ unsigned short Server::getPort() const // gibt den Port zur
|
|
|
return htons( addresse.sin_port );
|
|
|
}
|
|
|
|
|
|
+bool Server::isConnected() const // giebt 1 zurück, falls der Server verbunden ist
|
|
|
+{
|
|
|
+ return sock != 0;
|
|
|
+}
|
|
|
+
|
|
|
// Reference Counting
|
|
|
Server *Server::getThis()
|
|
|
{
|