view include/handler/INetworkHandler.hpp @ 50:307d75820a2d

Typo
author daedric <d43dr1c@gmail.com>
date Tue, 23 Mar 2010 10:56:40 +0100
parents dad671a5f028
children e16869cd9773
line wrap: on
line source

#ifndef __ZIA_API_HANDLER_INETWORKHANDLER_HPP__
# define __ZIA_API_HANDLER_INETWORKHANDLER_HPP__

# include <ios>

# include "network/IEndPoint.hpp"
# include "http/ITransaction.hpp"

namespace   zia
{
    namespace   api
    {
        namespace   handler
        {
            /**
             * @brief Interface for handlers which redefines some basic
             * functions like @b @c accept(2), @b @c write(2), @b @c read(2),
             * @b @c close(2).
             *
             * It allows protocol implementation like ssl.
             */
            class   INetworkHandler
            {
            public:
                /**
                 * @brief Agregate functions pointers that can be "overloaded".
                 *
                 * If a handler doesn't want to overload one of these functions
                 * it should set the pointer to @c NULL.
                 */
                struct sPtrFunc
                {
                    /**
                     * @brief Accept redefinition, called when we want to
                     * accept a new connection, sock_accept return a pointer on
                     * IEndPoint.
                     *
                     * @param [in] server Holds the accept socket.
                     *
                     * @return Null if an error occured. Otherwise the pointer
                     * returned MUST BE allocated using the new operator, which
                     * the server can delete later.
                     *
                     * @see network::IEndPoint
                     */
                    network::IEndPoint* (*sock_accept) (network::IEndPoint& server);

                    /**
                     * @brief Read redefinition, called when we want to read
                     * something on the socket
                     *
                     * @param [in] client Holds the client socket.
                     * @param [out] buffer Buffer that should be filled by the function.
                     * @param [in] len Buffer size.
                     *
                     * @return The number of bytes read, -1 on error and 0 on EOF.
                     *
                     * @see network::IEndPoint
                     */
                    ssize_t             (*sock_read)(network::IEndPoint& client, void* buffer, size_t len);

                    /**
                     * @brief Write redefinition, called when we want to write
                     * something on the socket.
                     *
                     * @param [in] client Holds the client socket.
                     * @param [out] buffer Buffer that have to be send.
                     * @param [in] len Buffer size.
                     *
                     * @return The number of bytes written, -1 on error and 0 on EOF.
                     *
                     * @see network::IEndPoint
                     */
                    ssize_t             (*sock_write)(network::IEndPoint& client, const void* buffer, size_t len);

                    /**
                     * @brief Close redefinition, called when we want to close the socket.
                     *
                     * @param [in] client Holds the client socket.
                     *
                     * @return 0 on success, -1 on failure.
                     */
                    int                 (*sock_close)(network::IEndPoint& client);
                };

                virtual ~INetworkHandler(void) { }

                /**
                 * @brief Return the structure wich contains all function
                 * pointers redefined.
                 *
                 * @return A copy of the structure.
                 *
                 * @see sPtrFunc
                 */
                virtual sPtrFunc    getNetworkHandlers(void) = 0;
            };
        };
    };
};

#endif	/* ! __ZIA_API_HANDLER_INETWORKHANDLER_HPP__ */