changeset 18:8ca7eb7a60fb

Change INetworkHandler
author daedric <d43dr1c@gmail.com>
date Sun, 21 Mar 2010 14:15:08 +0100
parents 2035bdfd2ca8
children 8619377761fd
files src/include/handler/INetworkHandler.hpp
diffstat 1 files changed, 43 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/include/handler/INetworkHandler.hpp	Sun Mar 21 00:06:12 2010 +0100
+++ b/src/include/handler/INetworkHandler.hpp	Sun Mar 21 14:15:08 2010 +0100
@@ -14,14 +14,53 @@
 
 namespace       handler
 {
-
+/**
+ * @brief this class represent an handler which redefine some basic function
+ * like accept(2), write(2), read(2)
+ *
+ * It allows protocol implementation like ssl
+ */
 class   INetworkHandler
 {
-public:
+    public:
+
+        /**
+         * @brief this structure represent functions pointers that can be overloaded
+         * if an handler does not want to overload one of this function it should set
+         * the pointer to NULL
+         *
+         */
+        struct sPtrFunc
+        {
+            /**
+             * sock_accept return a pointer on IEndpoint.
+             * if an error happend the pointer returned is null.
+             * the pointer HAS TO BE ALLOCATED, all memory managment is made by
+             * the server.
+             */
+            network::IEndPoint* (*sock_accept) (network::IEndPoint& server); /**< accept redefinition, called when we want accept a new connection */
 
-    virtual ~INetworkHandler(void){}
+            /**
+             * sock_read function returns the number of bytes read, -1 on error and 0 on EOF
+             */
+            int (*sock_read)(network::IEndPoint&, void* buffer, size_t len); /**< write redefinition, called when we want to write something on the socket */
+            /**
+             * sock_write function returns the number of bytes writen, -1 on error
+             */
+            int (*sock_write)(network::IEndPoint&, const void* buffer, size_t len);/**< read redefinition, called when we want to read something on the socket */
+        };
+
 
-    virtual int     operator()(network::IEndPoint & endpoint, std::ios & stream) = 0;
+
+        virtual ~INetworkHandler(void){}
+
+        /**
+         * @brief this method return the structure wich contains
+         * all function pointer redefined
+         * @return a copy of a structure
+         * @see sPtrFunc
+         */
+        virtual sPtrFunc getHandlers(void) = 0;
 
 };