summaryrefslogtreecommitdiffstats
path: root/src/Net/ClientConnection.cpp
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-05-15 17:30:40 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-05-15 17:30:40 +0200
commitc8d469cc3de8ef2fb95f7b47355ebf5318a4c22f (patch)
tree2cb0bd20306f89f3da11ff22b19865ed99225b2f /src/Net/ClientConnection.cpp
parent8324b947487f72fd8cfc439ea5ae5bd1187fff1b (diff)
downloadmad-c8d469cc3de8ef2fb95f7b47355ebf5318a4c22f.tar
mad-c8d469cc3de8ef2fb95f7b47355ebf5318a4c22f.zip
Einfache (ziemlich kaputte) Multithreaded IO
Diffstat (limited to 'src/Net/ClientConnection.cpp')
-rw-r--r--src/Net/ClientConnection.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/Net/ClientConnection.cpp b/src/Net/ClientConnection.cpp
index 0162a86..e4de735 100644
--- a/src/Net/ClientConnection.cpp
+++ b/src/Net/ClientConnection.cpp
@@ -29,6 +29,7 @@
namespace Mad {
namespace Net {
+// TODO Error handling
void ClientConnection::connectionHeaderReceiveHandler(const void *data, unsigned long length) {
if(length != sizeof(ConnectionHeader))
// Error... disconnect
@@ -55,15 +56,21 @@ void ClientConnection::connectionHeader() {
}
void ClientConnection::connect(const IPAddress &address, bool daemon0) throw(Exception) {
+ gl_rwlock_wrlock(stateLock);
+
daemon = daemon0;
- if(isConnected())
+ if(_isConnected()) {
+ gl_rwlock_unlock(stateLock);
return;
// TODO Error
+ }
sock = socket(PF_INET, SOCK_STREAM, 0);
- if(sock < 0)
+ if(sock < 0) {
+ gl_rwlock_unlock(stateLock);
throw Exception("socket()", Exception::INTERNAL_ERRNO, errno);
+ }
if(peer)
delete peer;
@@ -73,6 +80,8 @@ void ClientConnection::connect(const IPAddress &address, bool daemon0) throw(Exc
close(sock);
delete peer;
peer = 0;
+
+ gl_rwlock_unlock(stateLock);
throw Exception("connect()", Exception::INTERNAL_ERRNO, errno);
}
@@ -82,6 +91,7 @@ void ClientConnection::connect(const IPAddress &address, bool daemon0) throw(Exc
if(flags < 0) {
close(sock);
+ gl_rwlock_unlock(stateLock);
throw Exception("fcntl()", Exception::INTERNAL_ERRNO, errno);
}
@@ -96,9 +106,13 @@ void ClientConnection::connect(const IPAddress &address, bool daemon0) throw(Exc
gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred);
gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t)sock);
- FdManager::get()->registerFd(sock, sigc::mem_fun(this, &Connection::sendReceive));
+ FdManager::get()->registerFd(sock, sigc::mem_fun(this, &ClientConnection::sendReceive));
+
+ state = CONNECT;
+
+ gl_rwlock_unlock(stateLock);
- handshake();
+ updateEvents();
}
}