summaryrefslogtreecommitdiffstats
path: root/src/Net/ClientConnection.cpp
diff options
context:
space:
mode:
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);
+}
+
}
}