summaryrefslogtreecommitdiffstats
path: root/src/Net
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-06-25 03:16:01 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-06-25 03:16:01 +0200
commit725ed2a06c5e376168dc1552d52cf0b77ed5c073 (patch)
tree006605126f7089956405ef203c9ea3800e3f5f28 /src/Net
parentc97168bd5113fe726de42a4249df58c679e42240 (diff)
downloadmad-725ed2a06c5e376168dc1552d52cf0b77ed5c073.tar
mad-725ed2a06c5e376168dc1552d52cf0b77ed5c073.zip
Neuer Send-Stack
Diffstat (limited to 'src/Net')
-rw-r--r--src/Net/Connection.cpp32
-rw-r--r--src/Net/Connection.h7
-rw-r--r--src/Net/ServerConnection.cpp2
3 files changed, 31 insertions, 10 deletions
diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp
index 768d827..b0f505b 100644
--- a/src/Net/Connection.cpp
+++ b/src/Net/Connection.cpp
@@ -18,6 +18,7 @@
*/
#include "Connection.h"
+#include <cstring>
namespace Mad {
namespace Net {
@@ -94,23 +95,38 @@ bool Connection::rawReceive(unsigned long length,
return true;
}
-bool Connection::rawSend(const unsigned char *data, unsigned long length) {
+void Connection::doSend() {
if(!isConnected())
- return false;
+ return;
- while(length > 0) {
- ssize_t ret = gnutls_record_send(getSession(), data, length);
+ while(!sendQueueEmpty()) {
+ ssize_t ret = gnutls_record_send(getSession(), transS.front().data+transS.front().transmitted,
+ transS.front().length-transS.front().transmitted);
if(ret < 0) {
if(ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN)
- continue;
+ return;
- return false;
+ // Error... disconnect?
+ return;
}
- data += ret;
- length -= ret;
+ transS.front().transmitted += ret;
+
+ if(transS.front().transmitted == transS.front().length) {
+ delete [] transS.front().data;
+ transS.pop();
+ }
}
+}
+
+bool Connection::rawSend(const unsigned char *data, unsigned long length) {
+ if(!isConnected())
+ return false;
+
+ Transmission trans = {length, 0, new unsigned char[length], sigc::slot<void,const void*,unsigned long>()};
+ std::memcpy(trans.data, data, length);
+ transS.push(trans);
return true;
}
diff --git a/src/Net/Connection.h b/src/Net/Connection.h
index 7e73955..d13c2f6 100644
--- a/src/Net/Connection.h
+++ b/src/Net/Connection.h
@@ -43,6 +43,7 @@ class Connection {
};
Transmission transR;
+ std::queue<Transmission> transS;
Packet::Data header;
@@ -52,6 +53,7 @@ class Connection {
void packetDataReceiveHandler(const void *data, unsigned long length);
void doReceive();
+ void doSend();
bool receiveComplete() const {
return (transR.length == transR.transmitted);
@@ -84,10 +86,13 @@ class Connection {
return rawSend(reinterpret_cast<const unsigned char*>(packet.getRawData()), packet.getRawDataLength());
}
- void sendreceive() {
+ void sendReceive() {
doReceive();
+ doSend();
}
+ bool sendQueueEmpty() {return transS.empty();}
+
sigc::signal<void,const Connection*,const Packet&> signalReceive() const {return signal;}
static void init() {
diff --git a/src/Net/ServerConnection.cpp b/src/Net/ServerConnection.cpp
index 66274b4..afbfcbb 100644
--- a/src/Net/ServerConnection.cpp
+++ b/src/Net/ServerConnection.cpp
@@ -21,8 +21,8 @@
#include "IPAddress.h"
#include <cstring>
#include <cerrno>
-#include <fstream>
#include <sys/socket.h>
+#include <sys/select.h>
namespace Mad {
namespace Net {