diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-06-12 19:17:28 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-06-12 19:17:28 +0200 |
commit | 4b0778537ea5f1c4d7592639208e7c235abab260 (patch) | |
tree | e294a0c4753bea89692694434be2353ea205c66e /src/Net/Connection.cpp | |
parent | 5679977b5d22e22be9e4c47c4a3dcab90c1bc5a4 (diff) | |
download | mad-4b0778537ea5f1c4d7592639208e7c235abab260.tar mad-4b0778537ea5f1c4d7592639208e7c235abab260.zip |
Recieve-Funktion hinzugef?gt (ungetestet)
Diffstat (limited to 'src/Net/Connection.cpp')
-rw-r--r-- | src/Net/Connection.cpp | 69 |
1 files changed, 63 insertions, 6 deletions
diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp index 34b6ed6..bc38ed2 100644 --- a/src/Net/Connection.cpp +++ b/src/Net/Connection.cpp @@ -36,17 +36,74 @@ bool Connection::send(const Packet &packet) { if(ret < 0) { if(ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN) continue; - else - return false; - } - else { - data += ret; - dataLength -= ret; + + return false; } + + data += ret; + dataLength -= ret; } return true; } +bool Connection::recieve() { + unsigned char *headerData = reinterpret_cast<unsigned char*>(&header); + ssize_t ret; + + if(!isConnected()) + return false; + + while(true) { + if(!gnutls_record_check_pending(getSession())) + return false; + + if(read < sizeof(Packet::Data)) { + ret = gnutls_record_recv(getSession(), headerData+read, sizeof(Packet::Data)-read); + + if(ret < 0) { + if(ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN) + continue; + + return false; + } + + read += ret; + + if(read < sizeof(Packet::Data)) + continue; + + if(!header.length) { + Packet packet(header.type, header.requestId); + + return true; + } + + data = new unsigned char[header.length]; + } + + ret = gnutls_record_recv(getSession(), data+read-sizeof(Packet::Data), header.length+sizeof(Packet::Data)-read); + + if(ret < 0) { + if(ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN) + continue; + + return false; + } + + read += ret; + + if(read < header.length+sizeof(Packet::Data)) + continue; + + Packet packet(header.type, header.requestId, data, header.length); + + delete [] data; + data = 0; + + return true; + } +} + } } |