summaryrefslogtreecommitdiffstats
path: root/src/Net/ClientConnection.cpp
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-06-12 21:42:26 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-06-12 21:42:26 +0200
commitd2969d6f715949521e49a9b99c947ada86b1b49f (patch)
treebb3d0db8509cc2d44c5db174ec26755080639577 /src/Net/ClientConnection.cpp
parent4b0778537ea5f1c4d7592639208e7c235abab260 (diff)
downloadmad-d2969d6f715949521e49a9b99c947ada86b1b49f.tar
mad-d2969d6f715949521e49a9b99c947ada86b1b49f.zip
ServerConnection hinzugef?gt.
Diffstat (limited to 'src/Net/ClientConnection.cpp')
-rw-r--r--src/Net/ClientConnection.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/Net/ClientConnection.cpp b/src/Net/ClientConnection.cpp
index ea2e10e..1897b50 100644
--- a/src/Net/ClientConnection.cpp
+++ b/src/Net/ClientConnection.cpp
@@ -22,6 +22,7 @@
#include <cstring>
#include <cerrno>
#include <sys/socket.h>
+#include <sys/select.h>
namespace Mad {
namespace Net {
@@ -36,14 +37,16 @@ void ClientConnection::connect(const IPAddress &address) throw(ConnectionExcepti
if(sock < 0)
throw ConnectionException("socket()", std::strerror(errno));
- if(::connect(sock, peer->getSockAddr(), peer->getSockAddrLength()) < 0)
- throw ConnectionException("connect()", std::strerror(errno));
-
peer = new IPAddress(address);
+ if(::connect(sock, peer->getSockAddr(), peer->getSockAddrLength()) < 0) {
+ close(sock);
+ delete peer;
+ throw ConnectionException("connect()", std::strerror(errno));
+ }
+
connected = true;
- gnutls_anon_allocate_client_credentials(&anoncred);
gnutls_init(&session, GNUTLS_CLIENT);
gnutls_set_default_priority(session);
@@ -69,15 +72,26 @@ void ClientConnection::disconnect() {
shutdown(sock, SHUT_RDWR);
close(sock);
- sock = -1;
gnutls_deinit(session);
- gnutls_anon_free_client_credentials(anoncred);
delete peer;
connected = false;
}
+bool ClientConnection::dataPending() {
+ if(!connected)
+ return false;
+
+ fd_set fds;
+ FD_ZERO(&fds);
+ FD_SET(sock, &fds);
+
+ struct timeval timeout = {0, 0};
+
+ return (select(sock + 1, &fds, NULL, NULL, &timeout) == 1);
+}
+
}
}