--- a/src/Network/Node.cc Thu Dec 04 22:02:20 2008 +0000
+++ b/src/Network/Node.cc Thu Dec 04 22:14:45 2008 +0000
@@ -27,23 +27,34 @@
// delete this;
}
+void NetworkNode::write_packet_header (NetworkPacketOutput &pkt, NetworkChannelID channel_id) {
+ pkt.write_uint16(channel_id);
+}
+
+void NetworkNode::send_raw (const NetworkPacketBuffer &pkt, bool reliable) {
+ // either tcp or udp
+ if (reliable) {
+ assert(tcp);
+
+ tcp->write_packet(pkt);
+
+ } else {
+ udp->sendto(pkt, address);
+ }
+
+}
+
void NetworkNode::send (NetworkChannelID channel_id, const NetworkPacketBuffer &pkt, bool reliable) {
assert(channel_id > 0);
// add our header
NetworkPacket pkt2;
- pkt2.write_uint16(channel_id);
+
+ write_packet_header(pkt2, channel_id);
pkt2.write_packet(pkt);
- // either tcp or udp
- if (reliable) {
- assert(tcp);
-
- tcp->write_packet(pkt2);
-
- } else {
- udp->sendto(pkt2, address);
- }
+ // send
+ send_raw(pkt2, reliable);
}
const NetworkAddress& NetworkNode::getRemoteAddress (void) {
--- a/src/Network/Node.hh Thu Dec 04 22:02:20 2008 +0000
+++ b/src/Network/Node.hh Thu Dec 04 22:14:45 2008 +0000
@@ -35,6 +35,9 @@
CL_Signal_v0 _sig_disconnected;
public:
+ void write_packet_header (NetworkPacketOutput &pkt, NetworkChannelID channel_id);
+
+ void send_raw (const NetworkPacketBuffer &pkt, bool reliable = true);
void send (NetworkChannelID channel_id, const NetworkPacketBuffer &pkt, bool reliable = true);
const NetworkAddress& getRemoteAddress (void);
--- a/src/Network/Packet.cc Thu Dec 04 22:02:20 2008 +0000
+++ b/src/Network/Packet.cc Thu Dec 04 22:14:45 2008 +0000
@@ -164,3 +164,7 @@
}
+BigNetworkPacket::~BigNetworkPacket (void) {
+ free(buf_ptr);
+}
+
--- a/src/Network/Packet.hh Thu Dec 04 22:02:20 2008 +0000
+++ b/src/Network/Packet.hh Thu Dec 04 22:14:45 2008 +0000
@@ -147,6 +147,14 @@
class BigNetworkPacket : public NetworkPacketBuffer {
public:
BigNetworkPacket (size_t size);
+
+ private:
+ // no copies
+ BigNetworkPacket (const BigNetworkPacket &pkt);
+ BigNetworkPacket& operator= (const BigNetworkPacket &pkt);
+
+ protected:
+ virtual ~BigNetworkPacket (void);
};
#endif /* NETWORK_PACKET_HH */
--- a/src/Network/Session.hh Thu Dec 04 22:02:20 2008 +0000
+++ b/src/Network/Session.hh Thu Dec 04 22:14:45 2008 +0000
@@ -51,6 +51,7 @@
void send_all (NetworkChannelID channel_id, const NetworkPacketBuffer &pkt, bool reliable = true);
void send_all_except (NetworkChannelID channel_id, const NetworkPacketBuffer &pkt, const NetworkNode *node, bool reliable = true);
+
CL_Signal_v1<NetworkNode*>& sig_node_connected (void) { return _sig_node_connected; }
CL_Signal_v2<NetworkPacketInput&, NetworkNode *>& sig_chan_message (NetworkChannelID cid) { return _map_sig_chan_message[cid]; }
};
--- a/src/Network/UDP.cc Thu Dec 04 22:02:20 2008 +0000
+++ b/src/Network/UDP.cc Thu Dec 04 22:14:45 2008 +0000
@@ -56,7 +56,7 @@
} while (true);
}
-bool NetworkUDP::sendto (const NetworkPacket &packet, const NetworkAddress &dst) {
+bool NetworkUDP::sendto (const NetworkPacketBuffer &packet, const NetworkAddress &dst) {
int ret;
// XXX: shouldn't get trimmed
--- a/src/Network/UDP.hh Thu Dec 04 22:02:20 2008 +0000
+++ b/src/Network/UDP.hh Thu Dec 04 22:14:45 2008 +0000
@@ -21,7 +21,7 @@
CL_Signal_v2<NetworkPacketInput&, const NetworkAddress&> _sig_packet;
public:
- bool sendto (const NetworkPacket &packet, const NetworkAddress &dst);
+ bool sendto (const NetworkPacketBuffer &packet, const NetworkAddress &dst);
CL_Signal_v2<NetworkPacketInput&, const NetworkAddress&>& sig_packet (void) { return _sig_packet; }
};