summaryrefslogtreecommitdiff
path: root/src/common/network.h
diff options
context:
space:
mode:
authorbrianluau <brianluau@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-12-05 02:53:33 +0000
committerbrianluau <brianluau@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-12-05 02:53:33 +0000
commit60a426c0742b3e7d8c5b557c7578df6eeeea377b (patch)
tree5d01f9ccc2798309f9b13f07c0096ed97c6a85c8 /src/common/network.h
parent621db2441f69736a6c8f10d26bf966d5414fac74 (diff)
downloadhercules-60a426c0742b3e7d8c5b557c7578df6eeeea377b.tar.gz
hercules-60a426c0742b3e7d8c5b557c7578df6eeeea377b.tar.bz2
hercules-60a426c0742b3e7d8c5b557c7578df6eeeea377b.tar.xz
hercules-60a426c0742b3e7d8c5b557c7578df6eeeea377b.zip
- Undid r16968: SVN Replaced with source:/trunk/src/@16966 (tid:74924).
[16969:16991/trunk/src/] will be re-committed in the next 24 hours. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16992 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/network.h')
-rw-r--r--src/common/network.h220
1 files changed, 110 insertions, 110 deletions
diff --git a/src/common/network.h b/src/common/network.h
index b883b41e6..d7b463a2f 100644
--- a/src/common/network.h
+++ b/src/common/network.h
@@ -3,7 +3,7 @@
#include <netinet/in.h>
#include "../common/cbasetypes.h"
-#include "../common/netbuffer.h"
+#include "../common/netbuffer.h"
#include "../common/evdp.h"
#ifndef MAXCONN
@@ -11,79 +11,79 @@
#endif
-typedef struct SESSION {
- EVDP_DATA evdp_data; // Must be always the frist member! (some evdp's may rely on this fact)
-
- // Connection Type
- enum { NST_FREE=0, NST_LISTENER = 1, NST_CLIENT=2, NST_OUTGOING=3} type;
-
- // Flags / Settings.
- bool v6; // is v6?
- bool disconnect_in_progress; // To prevent stack overflows / recursive calls.
-
-
- union { // union to save memory.
- struct sockaddr_in v4;
- struct sockaddr_in6 v6;
- } addr;
-
-
- // "lowlevel" Handlers
- // (Implemented by the protocol specific parser)
- //
- bool (*onRecv)(int32 fd); // return false = disconnect
- bool (*onSend)(int32 fd); // return false = disconnect
-
- // Event Handlers for LISTENER type sockets
- //
- // onConnect gets Called when a connection has been
- // successfully accepted.
- // Session entry is available in this Handler!
- // A returncode of false will reejct the connection (disconnect)
- // Note: When rejecting a connection in onConnect by returning false
- // The onDisconnect handler wont get called!
- // Note: the onConnect Handler is also responsible for setting
- // the appropriate netparser (which implements onRecv/onSend..) [protocol specific]
- //
- // onDisconnect gets called when a connection gets disconnected
- // (by peer as well as by core)
- //
- bool (*onConnect)(int32 fd); // return false = disconnect (wont accept)
- void (*onDisconnect)(int32 fd);
-
-
- //
- // Parser specific data
- //
- void *netparser_data; // incase of RO Packet Parser, pointer to packet len table (uint16array)
- void (*onPacketComplete)(int32 fd, uint16 op, uint16 len, netbuf buf);
-
-
- //
- // Buffers
- //
- struct {
- enum NETREADSTATE { NRS_WAITOP = 0, NRS_WAITLEN = 1, NRS_WAITDATA = 2} state;
-
- uint32 head_left;
- uint16 head[2];
-
- netbuf buf;
- } read;
-
- struct {
- uint32 max_outstanding;
- uint32 n_outstanding;
-
- uint32 dataPos;
-
- netbuf buf, buf_last;
- } write;
-
- // Application Level data Pointer
- // (required for backward compatibility with previous athena socket system.)
- void *data;
-
+typedef struct SESSION{
+ EVDP_DATA evdp_data; // Must be always the frist member! (some evdp's may rely on this fact)
+
+ // Connection Type
+ enum{ NST_FREE=0, NST_LISTENER = 1, NST_CLIENT=2, NST_OUTGOING=3} type;
+
+ // Flags / Settings.
+ bool v6; // is v6?
+ bool disconnect_in_progress; // To prevent stack overflows / recursive calls.
+
+
+ union{ // union to save memory.
+ struct sockaddr_in v4;
+ struct sockaddr_in6 v6;
+ }addr;
+
+
+ // "lowlevel" Handlers
+ // (Implemented by the protocol specific parser)
+ //
+ bool (*onRecv)(int32 fd); // return false = disconnect
+ bool (*onSend)(int32 fd); // return false = disconnect
+
+ // Event Handlers for LISTENER type sockets
+ //
+ // onConnect gets Called when a connection has been
+ // successfully accepted.
+ // Session entry is available in this Handler!
+ // A returncode of false will reejct the connection (disconnect)
+ // Note: When rejecting a connection in onConnect by returning false
+ // The onDisconnect handler wont get called!
+ // Note: the onConnect Handler is also responsible for setting
+ // the appropriate netparser (which implements onRecv/onSend..) [protocol specific]
+ //
+ // onDisconnect gets called when a connection gets disconnected
+ // (by peer as well as by core)
+ //
+ bool (*onConnect)(int32 fd); // return false = disconnect (wont accept)
+ void (*onDisconnect)(int32 fd);
+
+
+ //
+ // Parser specific data
+ //
+ void *netparser_data; // incase of RO Packet Parser, pointer to packet len table (uint16array)
+ void (*onPacketComplete)(int32 fd, uint16 op, uint16 len, netbuf buf);
+
+
+ //
+ // Buffers
+ //
+ struct{
+ enum NETREADSTATE { NRS_WAITOP = 0, NRS_WAITLEN = 1, NRS_WAITDATA = 2} state;
+
+ uint32 head_left;
+ uint16 head[2];
+
+ netbuf buf;
+ } read;
+
+ struct{
+ uint32 max_outstanding;
+ uint32 n_outstanding;
+
+ uint32 dataPos;
+
+ netbuf buf, buf_last;
+ } write;
+
+ // Application Level data Pointer
+ // (required for backward compatibility with previous athena socket system.)
+ void *data;
+
} SESSION;
@@ -101,12 +101,12 @@ void network_final();
void network_do();
-/**
+/**
* Adds a new listner.
*
- * @param v6 v6 listner?
- * @param *addr the address to listen on.
- * @param port port to listen on
+ * @param v6 v6 listner?
+ * @param *addr the address to listen on.
+ * @param port port to listen on
*
* @return -1 on error otherwise the identifier of the new listener.
*/
@@ -116,26 +116,26 @@ int32 network_addlistener(bool v6, const char *addr, uint16 port);
/**
* Tries to establish an outgoing connection.
*
- * @param v6 operate with IPv6 addresses?
- * @param addr the address to connect to
- * @param port the port to connect to
- * @param from_addr the address to connect from (local source / optional if auto -> NULL)
+ * @param v6 operate with IPv6 addresses?
+ * @param addr the address to connect to
+ * @param port the port to connect to
+ * @param from_addr the address to connect from (local source / optional if auto -> NULL)
* @param from_port the port to connect from (local source / optional if auto -> 0)
- * @param onConnectionEstablishedHandler callback that gets called when the connection is established.
- * @param onConnectionLooseHandler callback that gets called when the connection gets disconnected (or the connection couldnt be established)
+ * @param onConnectionEstablishedHandler callback that gets called when the connection is established.
+ * @param onConnectionLooseHandler callback that gets called when the connection gets disconnected (or the connection couldnt be established)
*
* @return -1 on error otherwise the identifier of the new connection
*/
int32 network_connect(bool v6,
- const char *addr,
- uint16 port,
- const char *from_addr,
- uint16 from_port,
- bool (*onConnectionEstablishedHandler)(int32 fd),
- void (*onConnectionLooseHandler)(int32 fd)
- );
-
+ const char *addr,
+ uint16 port,
+ const char *from_addr,
+ uint16 from_port,
+ bool (*onConnectionEstablishedHandler)(int32 fd),
+ void (*onConnectionLooseHandler)(int32 fd)
+);
+
/**
* Disconnects the given connection
@@ -143,43 +143,43 @@ int32 network_connect(bool v6,
* @param fd connection identifier.
*
* @Note:
- * - onDisconnect callback gets called!
- * - cleares (returns) all assigned buffers
+ * - onDisconnect callback gets called!
+ * - cleares (returns) all assigned buffers
*
*/
void network_disconnect(int32 fd);
-/**
+/**
* Attach's a netbuffer at the end of sending queue to the given connection
*
- * @param fd connection identifier
- * @param buf netbuffer to attach.
+ * @param fd connection identifier
+ * @param buf netbuffer to attach.
*/
void network_send(int32 fd, netbuf buf);
/**
* Sets the parser to RO Protocol like Packet Parser.
- *
- * @param fd connection identifier
- * @param *packetlentable pointer to array of uint16 in size of UINT16_MAX,
- * @param onComplteProc callback for packet completion.
+ *
+ * @param fd connection identifier
+ * @param *packetlentable pointer to array of uint16 in size of UINT16_MAX,
+ * @param onComplteProc callback for packet completion.
*
* @note:
- * PacketLen Table Fromat:
- * each element's offsets represents th ro opcode.
- * value is length.
- * a length of 0 means the packet is dynamic.
- * a length of UINT16_MAX means the packet is unknown.
+ * PacketLen Table Fromat:
+ * each element's offsets represents th ro opcode.
+ * value is length.
+ * a length of 0 means the packet is dynamic.
+ * a length of UINT16_MAX means the packet is unknown.
*
- * Static Packets must contain their hader in len so (0x64 == 55 ..)
+ * Static Packets must contain their hader in len so (0x64 == 55 ..)
*
*/
void network_parser_set_ro(int32 fd,
- int16 *packetlentable,
- void (*onPacketCompleteProc)(int32 fd, uint16 op, uint16 len, netbuf buf)
- );
+ int16 *packetlentable,
+ void (*onPacketCompleteProc)(int32 fd, uint16 op, uint16 len, netbuf buf)
+ );
#define ROPACKET_UNKNOWN UINT16_MAX
#define ROPACKET_DYNLEN 0