|
From: <mrv...@us...> - 2007-06-02 08:20:22
|
Revision: 25
http://svn.sourceforge.net/dawnofinfinity/?rev=25&view=rev
Author: mrvacbob
Date: 2007-06-02 01:20:20 -0700 (Sat, 02 Jun 2007)
Log Message:
-----------
function bodies, some destructor calling
Modified Paths:
--------------
trunk/Makefile.am
trunk/net.cpp
trunk/net.h
trunk/queue.h
trunk/set.h
trunk/tests.cpp
Modified: trunk/Makefile.am
===================================================================
--- trunk/Makefile.am 2007-06-02 08:16:10 UTC (rev 24)
+++ trunk/Makefile.am 2007-06-02 08:20:20 UTC (rev 25)
@@ -11,7 +11,7 @@
#SUBDIRS = tester
-tester_SOURCES = tests.cpp utils.cpp object.cpp list.cpp
+tester_SOURCES = tests.cpp utils.cpp object.cpp list.cpp net.cpp
#tester_LDADD =
maintainer-clean-generic:
Modified: trunk/net.cpp
===================================================================
--- trunk/net.cpp 2007-06-02 08:16:10 UTC (rev 24)
+++ trunk/net.cpp 2007-06-02 08:20:20 UTC (rev 25)
@@ -0,0 +1,66 @@
+/*
+ *
+ * Copyright (C) 2003 and beyond by Alexander Strange
+ * and the Dawn Of Infinity developers.
+ *
+ * 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.
+ *
+ * This license is contained in the file "COPYING",
+ * which is included with this source code; it is available online at
+ * http://www.gnu.org/licenses/gpl.html
+ *
+ */
+
+#include "net.h"
+
+void Connection::enqueue(Packet p, enum tcp_udp pt)
+{
+ (pt == p_tcp ? transmitq_tcp : transmitq_udp).push(p);
+ FD_SET((pt == p_tcp ? sock : sock_udp), &parent->parent->writing_fds);
+}
+
+void Connection::task()
+{
+}
+
+ConnectionGroup::ConnectionGroup(ConnCallback *cc, Net *parent) : callback(cc), parent(parent)
+{
+}
+
+ConnectionGroup::~ConnectionGroup()
+{
+}
+
+void ConnectionGroup::broadcastexceptfor(Packet p, Connection *c, enum tcp_udp pt)
+{
+}
+
+void ConnectionGroup::broadcast(Packet p, enum tcp_udp pt)
+{
+ broadcastexceptfor(p, NULL, pt);
+}
+
+Net::Net(const char *port, NewConnCallback *cc) : port(port), ncc(cc)
+{
+}
+
+Net::~Net()
+{
+}
+
+void Net::addgroup(ConnCallback *cc)
+{
+ cgroups.add(ConnectionGroup(cc, this));
+}
+
+void Net::task()
+{
+}
\ No newline at end of file
Modified: trunk/net.h
===================================================================
--- trunk/net.h 2007-06-02 08:16:10 UTC (rev 24)
+++ trunk/net.h 2007-06-02 08:20:20 UTC (rev 25)
@@ -26,21 +26,36 @@
#ifndef _NET_H
#define _NET_H
+#include "utils.h"
+#include "queue.h"
+#include "set.h"
-typedef union packetinternals {
- struct {
- uint16_t type;
- uint16_t size;
+struct packetinternals : public Object
+{
+ union {
+ struct {
+ uint16_t type;
+ uint16_t size;
+ };
+
+ unsigned char data[0];
};
-
- unsigned char data[0];
-} *Packet;
+};
+typedef struct packetinternals *Packet;
+struct ConnCallbackContext {};
+
+struct ConnCallback {
+ virtual void handlepacket(Packet *p) = 0;
+};
+
+enum tcp_udp {p_tcp, p_udp};
+
struct Connection : public Object
{
Queue<Packet> transmitq_tcp, transmitq_udp;
- Packet *curp, *curp_udp;
+ Packet curp, curp_udp;
int sock, sock_udp;
@@ -49,21 +64,35 @@
struct ConnectionGroup *parent;
- Packet *recievebuf;
+ Packet recievebuf;
struct ConnCallbacKContext *ccontext;
+
+ void enqueue(Packet p, enum tcp_udp pt = p_tcp);
+ void task();
};
+struct NewConnCallback {
+ virtual void handleconn(Connection *c) = 0;
+};
+
/// Handles multicasting and callbacks. One per system.
struct ConnectionGroup : public Object
{
Set<Connection> connections;
struct ConnCallback *callback;
+ struct Net *parent;
+
+ ConnectionGroup(ConnCallback *cc, Net *parent);
+ ~ConnectionGroup();
+
+ void broadcast(Packet p, enum tcp_udp pt = p_tcp);
+ void broadcastexceptfor(Packet p, Connection *c, enum tcp_udp pt = p_tcp);
};
/// Listen to listening socket, poll clients. One per port.
-struct NetInterface : public Object
+struct Net : public Object
{
fd_set active_fds;
fd_set writing_fds;
@@ -73,7 +102,15 @@
long highfd;
const char *port; // what does this do
+ NewConnCallback *ncc;
+
Set<ConnectionGroup> cgroups;
+
+ Net(const char *port, NewConnCallback *cc);
+ ~Net();
+
+ void addgroup(ConnCallback *cc);
+ void task();
};
#endif
\ No newline at end of file
Modified: trunk/queue.h
===================================================================
--- trunk/queue.h 2007-06-02 08:16:10 UTC (rev 24)
+++ trunk/queue.h 2007-06-02 08:20:20 UTC (rev 25)
@@ -64,6 +64,7 @@
~Queue() {data = NULL;}
void clear(size_t i) {
+ data[i].~T();
memset(&data[i], 0, sizeof(T));
}
@@ -96,24 +97,28 @@
return s.str();
}
- void grow() {
- size_t newsize = allocated + 16;
+ void grow();
+};
+
+template<typename T>
+void Queue<T>::grow()
+{
+ size_t newsize = allocated + 16;
+
+ if (begin == 0) {
+ data = (T*)GC_realloc(data, sizeof(T[newsize]));
+ } else {
+ T *ndata = (T*)GC_malloc(sizeof(T[newsize]));
- if (begin == 0) {
- data = (T*)GC_realloc(data, sizeof(T[newsize]));
- } else {
- T *ndata = (T*)GC_malloc(sizeof(T[newsize]));
-
- memcpy(ndata, &data[begin], sizeof(T[allocated - begin]));
- memcpy(&ndata[allocated - begin], data, sizeof(T[end]));
-
- data = ndata;
- }
+ memcpy(ndata, &data[begin], sizeof(T[allocated - begin]));
+ memcpy(&ndata[allocated - begin], data, sizeof(T[end]));
- memset(&data[allocated],0,sizeof(T[newsize - allocated]));
- allocated = newsize;
+ data = ndata;
}
-};
+
+ memset(&data[allocated],0,sizeof(T[newsize - allocated]));
+ allocated = newsize;
+}
typedef Queue<const void *> PQueue;
#endif
Modified: trunk/set.h
===================================================================
--- trunk/set.h 2007-06-02 08:16:10 UTC (rev 24)
+++ trunk/set.h 2007-06-02 08:20:20 UTC (rev 25)
@@ -74,7 +74,7 @@
}
~Set () {data = NULL;}
- void clear(size_t i) {memset(&data[i], 0, sizeof(T));}
+ void clear(size_t i) {data[i].~T(); memset(&data[i], 0, sizeof(T));}
void add(const T &p) {
if (allocated == filled) grow();
Modified: trunk/tests.cpp
===================================================================
--- trunk/tests.cpp 2007-06-02 08:16:10 UTC (rev 24)
+++ trunk/tests.cpp 2007-06-02 08:20:20 UTC (rev 25)
@@ -38,11 +38,8 @@
printf("\n");
}
-NetInterface *n;
-
void test_net()
{
- n = new NetInterface();
}
#undef main
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|