summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Net/Connection.cpp32
-rw-r--r--src/Net/Connection.h7
-rw-r--r--src/Net/ServerConnection.cpp2
-rw-r--r--src/mad-core.cpp2
-rw-r--r--src/madc.cpp3
5 files changed, 35 insertions, 11 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 {
diff --git a/src/mad-core.cpp b/src/mad-core.cpp
index 04b18cc..830f26a 100644
--- a/src/mad-core.cpp
+++ b/src/mad-core.cpp
@@ -42,7 +42,7 @@ int main() {
try {
connection.listen(Mad::Net::IPAddress("0.0.0.0", 6666));
- while(running) connection.sendreceive();
+ while(running) connection.sendReceive();
}
catch(Mad::Net::Exception &e) {
std::cerr << "Connection error: " << e.what() << std::endl;
diff --git a/src/madc.cpp b/src/madc.cpp
index 9d525b2..0c28793 100644
--- a/src/madc.cpp
+++ b/src/madc.cpp
@@ -30,6 +30,9 @@ int main() {
try {
connection.connect(Mad::Net::IPAddress("127.0.0.1", 6666));
connection.send(Mad::Net::Packet(0x0001, 0xABCD));
+
+ while(!connection.sendQueueEmpty())
+ connection.sendReceive();
}
catch(Mad::Net::Exception &e) {
std::cerr << "Connection error: " << e.what() << std::endl;