summaryrefslogtreecommitdiff
path: root/src/netcomputer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/netcomputer.cpp')
-rw-r--r--src/netcomputer.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/netcomputer.cpp b/src/netcomputer.cpp
index 79110fd4..bffe7b86 100644
--- a/src/netcomputer.cpp
+++ b/src/netcomputer.cpp
@@ -22,15 +22,43 @@
*/
#include "netcomputer.h"
-
+#include <cstdlib>
+#include <iostream>
NetComputer::NetComputer(ConnectionHandler *handler):
handler(handler)
{
}
+NetComputer::~NetComputer()
+{
+ // delete unsent messages
+ while (queue.size() > 0) {
+ delete queue.front();
+ queue.pop();
+ }
+}
+
void NetComputer::disconnect(const std::string &reason)
{
// Somehow notify the netsession listener about the disconnect after
// sending this computer a disconnect message containing the reason.
}
+
+void NetComputer::send(const Packet *p)
+{
+ // Copy the packet
+ Packet *newPacket = new Packet(NULL, 0);
+ newPacket->data = new char[p->length];
+ memcpy(newPacket->data, (void*) p->data, p->length);
+ newPacket->length = p->length;
+
+ queue.push(newPacket);
+}
+
+Packet *NetComputer::front()
+{
+ Packet *ret = queue.front();
+ queue.pop();
+ return ret;
+}