summaryrefslogtreecommitdiff
path: root/src/common/netbuffer.h
diff options
context:
space:
mode:
authorblacksirius <blacksirius@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-06-12 00:59:55 +0000
committerblacksirius <blacksirius@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-06-12 00:59:55 +0000
commit49586af4b75b96010380576fe9ce0a9b67a83ac2 (patch)
treeafebe591c3a1a372f66422f495f5e1fd0538032e /src/common/netbuffer.h
parent0598cc569db02ee93d7fc0470defecb64e995f5c (diff)
downloadhercules-49586af4b75b96010380576fe9ce0a9b67a83ac2.tar.gz
hercules-49586af4b75b96010380576fe9ce0a9b67a83ac2.tar.bz2
hercules-49586af4b75b96010380576fe9ce0a9b67a83ac2.tar.xz
hercules-49586af4b75b96010380576fe9ce0a9b67a83ac2.zip
added new networking subsystem (early stage - files are not compiled yet during normal build!)
Note The files i added / modifications i did, are not affecting a normal build nothing gets changed yet! Linux 2.5+ only yet. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16271 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/netbuffer.h')
-rw-r--r--src/common/netbuffer.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/common/netbuffer.h b/src/common/netbuffer.h
new file mode 100644
index 000000000..844241226
--- /dev/null
+++ b/src/common/netbuffer.h
@@ -0,0 +1,83 @@
+// Copyright (c) rAthena Project (www.rathena.org) - Licensed under GNU GPL
+// For more information, see LICENCE in the main folder
+
+#ifndef _rA_NETBUFFER_H_
+#define _rA_NETBUFFER_H_
+
+#include "../common/cbasetypes.h"
+
+typedef struct netbuf{
+ sysint pool; // The pool ID this buffer belongs to,
+ // is set to -1 if its an emergency allocated buffer
+
+ struct netbuf *next; // Used by Network system.
+
+ volatile int32 refcnt; // Internal Refcount, it gets lowered every call to netbuffer_put,
+ // if its getting zero, the buffer will returned back to the pool
+ // and can be reused.
+
+ int32 dataPos; // Current Offset
+ // Used only for Reading (recv job)
+ // write cases are using the sessions local datapos member due to
+ // shared write buffer support.
+
+ int32 dataLen; // read buffer case:
+ // The length expected to read to.
+ // when this->dataPos == dateLen, read job has been completed.
+ // write buffer case:
+ // The lngth of data in te buffer
+ // when s->dataPos == dataLen, write job has been completed
+ //
+ // Note:
+ // leftBytes = (dateLen - dataPos)
+ //
+ // Due to shared buffer support
+ // dataPos gets not used in write case (each connection has its local offset)
+ //
+
+ // The Bufferspace itself.
+ char buf[32];
+} *netbuf;
+
+
+void netbuffer_init();
+void netbuffer_final();
+
+/**
+ * Gets a netbuffer that has atleast (sz) byes space.
+ *
+ * @note: The netbuffer system guarantees that youll always recevie a buffer.
+ * no check for null is required!
+ *
+ * @param sz - minimum size needed.
+ *
+ * @return pointer to netbuf struct
+ */
+netbuf netbuffer_get( sysint sz );
+
+
+/**
+ * Returns the given netbuffer (decreases refcount, if its 0 - the buffer will get returned to the pool)
+ *
+ * @param buf - the buffer to return
+ */
+void netbuffer_put( netbuf buf );
+
+
+/**
+ * Increases the Refcount on the given buffer
+ * (used for areasends .. etc)
+ *
+ */
+void netbuffer_incref( netbuf buf );
+
+
+// Some Useful macros
+#define NBUFP(netbuf,pos) (((uint8*)(netbuf->buf)) + (pos))
+#define NBUFB(netbuf,pos) (*(uint8*)((netbuf->buf) + (pos)))
+#define NBUFW(netbuf,pos) (*(uint16*)((netbuf->buf) + (pos)))
+#define NBUFL(netbuf,pos) (*(uint32*)((netbuf->buf) + (pos)))
+
+
+
+#endif