summaryrefslogtreecommitdiff
path: root/src/net_io.c
diff options
context:
space:
mode:
authorSimon Howard2005-10-30 19:56:15 +0000
committerSimon Howard2005-10-30 19:56:15 +0000
commit59c7b8446575847ddf9b22b9b93a4eb58b7fe042 (patch)
tree6adc4b3b47de4f090b2330f0e7b6dce660d0fae6 /src/net_io.c
parent1e9ce0901c8439ebb3299b77690cd7cd4ccf25b0 (diff)
downloadchocolate-doom-59c7b8446575847ddf9b22b9b93a4eb58b7fe042.tar.gz
chocolate-doom-59c7b8446575847ddf9b22b9b93a4eb58b7fe042.tar.bz2
chocolate-doom-59c7b8446575847ddf9b22b9b93a4eb58b7fe042.zip
Add foundation code for the new networking system
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 229
Diffstat (limited to 'src/net_io.c')
-rw-r--r--src/net_io.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/net_io.c b/src/net_io.c
new file mode 100644
index 00000000..b0a56025
--- /dev/null
+++ b/src/net_io.c
@@ -0,0 +1,122 @@
+// Emacs style mode select -*- C++ -*-
+//-----------------------------------------------------------------------------
+//
+// $Id: net_io.c 229 2005-10-30 19:56:15Z fraggle $
+//
+// Copyright(C) 2005 Simon Howard
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+// 02111-1307, USA.
+//
+// $Log$
+// Revision 1.1 2005/10/30 19:56:15 fraggle
+// Add foundation code for the new networking system
+//
+//
+// DESCRIPTION:
+// Network packet I/O. Base layer for sending/receiving packets,
+// through the network module system
+//
+//-----------------------------------------------------------------------------
+
+#include "i_system.h"
+#include "net_defs.h"
+#include "net_io.h"
+#include "z_zone.h"
+
+#define MAX_MODULES 16
+
+struct _net_context_s
+{
+ net_module_t *modules[MAX_MODULES];
+ int num_modules;
+};
+
+net_context_t *NET_NewContext(void)
+{
+ net_context_t *context;
+
+ context = Z_Malloc(sizeof(net_context_t), PU_STATIC, 0);
+ context->num_modules = 0;
+
+ return context;
+}
+
+void NET_AddModule(net_context_t *context, net_module_t *module)
+{
+ if (context->num_modules >= MAX_MODULES)
+ {
+ I_Error("NET_AddModule: No more modules for context");
+ }
+
+ context->modules[context->num_modules] = module;
+ ++context->num_modules;
+}
+
+net_addr_t *NET_ResolveAddress(net_context_t *context, char *addr)
+{
+ int i;
+ net_addr_t *result;
+
+ result = NULL;
+
+ for (i=0; i<context->num_modules; ++i)
+ {
+ result = context->modules[i]->ResolveAddress(addr);
+
+ if (result != NULL)
+ {
+ break;
+ }
+ }
+
+ return result;
+}
+
+void NET_SendPacket(net_addr_t *addr, net_packet_t *packet)
+{
+ addr->module->SendPacket(addr, packet);
+}
+
+boolean NET_RecvPacket(net_context_t *context,
+ net_addr_t **addr,
+ net_packet_t **packet)
+{
+ int i;
+
+ // check all modules for new packets
+
+ for (i=0; i<context->num_modules; ++i)
+ {
+ if (context->modules[i]->RecvPacket(addr, packet))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void NET_AddrToString(net_addr_t *addr, char *buffer, int buffer_len)
+{
+ addr->module->AddrToString(addr, buffer, buffer_len);
+}
+
+void NET_FreeAddress(net_addr_t *addr)
+{
+ addr->module->FreeAddress(addr);
+}
+
+