#load "core/std"
-#load "src/module"
+#load "./../src/module"
use package core
onyx_net :: package onyx_net
if it.data == "What's Up?" {
packet := new(onyx_net.Packet);
packet.flags |= .Reliable;
- packet.data = #file_contents "src/host.onyx";
+ packet.data = #file_contents "./../src/host.onyx";
onyx_net.peer_send(it.peer, 0, packet);
}
flags: Flags;
data: [] u8;
+
+ // Set this to true to have the internal code
+ // free the data when it is done with the packet.
+ free_data := false;
+
+ // The allocator used for the data. Only used if
+ // free_data is set to true.
+ data_allocator := context.allocator;
}
Acknowledgement :: struct {
if (it.command.command & .Flag_Acknowledge) != 0 {
peer.sent_reliable_commands << it;
+ } else {
+ peer_free_outgoing_command(peer, it);
}
}
if command == null do return .None;
- defer {
- cfree(command.command);
- cfree(command);
- }
+ defer peer_free_outgoing_command(peer, command);
return command_get_effective(command.command.command);
}
+peer_free_outgoing_command :: (peer: ^Peer, command: ^Outgoing_Command) {
+ if command.packet.free_data {
+ raw_free(command.packet.data_allocator, command.packet.data.data);
+ }
+
+ if command.packet != null do cfree(command.packet);
+ cfree(command.command);
+ cfree(command);
+}
+
Channel_ID :: u8;