summaryrefslogtreecommitdiffstats
path: root/src/Net/ClientConnection.cpp
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-06-12 19:17:28 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-06-12 19:17:28 +0200
commit4b0778537ea5f1c4d7592639208e7c235abab260 (patch)
treee294a0c4753bea89692694434be2353ea205c66e /src/Net/ClientConnection.cpp
parent5679977b5d22e22be9e4c47c4a3dcab90c1bc5a4 (diff)
downloadmad-4b0778537ea5f1c4d7592639208e7c235abab260.tar
mad-4b0778537ea5f1c4d7592639208e7c235abab260.zip
Recieve-Funktion hinzugef?gt (ungetestet)
Diffstat (limited to 'src/Net/ClientConnection.cpp')
-rw-r--r--src/Net/ClientConnection.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/Net/ClientConnection.cpp b/src/Net/ClientConnection.cpp
index 66df2ea..ea2e10e 100644
--- a/src/Net/ClientConnection.cpp
+++ b/src/Net/ClientConnection.cpp
@@ -32,8 +32,6 @@ void ClientConnection::connect(const IPAddress &address) throw(ConnectionExcepti
if(connected)
disconnect();
- peer = new IPAddress(address);
-
sock = socket(PF_INET, SOCK_STREAM, 0);
if(sock < 0)
throw ConnectionException("socket()", std::strerror(errno));
@@ -41,6 +39,10 @@ void ClientConnection::connect(const IPAddress &address) throw(ConnectionExcepti
if(::connect(sock, peer->getSockAddr(), peer->getSockAddrLength()) < 0)
throw ConnectionException("connect()", std::strerror(errno));
+ peer = new IPAddress(address);
+
+ connected = true;
+
gnutls_anon_allocate_client_credentials(&anoncred);
gnutls_init(&session, GNUTLS_CLIENT);
@@ -52,10 +54,11 @@ void ClientConnection::connect(const IPAddress &address) throw(ConnectionExcepti
gnutls_transport_set_ptr(session, reinterpret_cast<gnutls_transport_ptr_t>(sock));
int ret = gnutls_handshake(session);
- if(ret < 0)
+ if(ret < 0) {
+ disconnect();
+
throw ConnectionException("gnutls_handshake()", gnutls_strerror(ret));
-
- connected = true;
+ }
}
void ClientConnection::disconnect() {
@@ -64,19 +67,14 @@ void ClientConnection::disconnect() {
gnutls_bye(session, GNUTLS_SHUT_RDWR);
- if(sock >= 0) {
- shutdown(sock, SHUT_RDWR);
- close(sock);
- sock = -1;
- }
+ shutdown(sock, SHUT_RDWR);
+ close(sock);
+ sock = -1;
gnutls_deinit(session);
gnutls_anon_free_client_credentials(anoncred);
- if(peer) {
- delete peer;
- peer = 0;
- }
+ delete peer;
connected = false;
}