[Home]BoostSocket/DataSocketConcept

BOOST WIKI | BoostSocket | RecentChanges | Preferences | Page List | Links List

Data Socket Concept

A data socket is created by an acceptor sockect or by a connector

An interface like the one below has some advantages:

    template<typename PROTOCOL, typename ADDRESS = PROTOCOL::address_type_tl::head>
    struct data_connection
    {
        typedef PROTOCOL protocol_t;
        typedef ADDRESS address_t;
        typedef boost::posix_time::time_duration duration_t;

        struct result
        {
            enum enum_t
            {
                success,
                partial,
                disconnected,
                would_block,
                .... other common errcodes
                specific_error
            }
        };

        data_connection(protocol_t protocol = protocol_t());

        /// blocking
        std::pair<result::enum_t,unsigned> send(void*, unsigned int);
        std::pair<result::enum_t,unsigned> receive(void* data, unsigned int byteCount);
        std::pair<result::enum_t,unsigned> receive_full(void*, unsigned int byteCount);

        /// non blocking
        std::pair<result::enum_t,unsigned> send(void*, unsigned int, duration_t timeoutSecs);
        std::pair<result::enum_t,unsigned> receive(void* data, unsigned int byteCount, duration_t timeoutSecs);
        std::pair<result::enum_t,unsigned> receive_full(void*, unsigned int byteCount, duration_t timeoutSecs);

        const address_t& local_address() const;
        const address_t& remote_address() const;

        void close();

        result::enum_t shutdown(Direction how=Both)
        bool is_valid() const

        bool operator<(const data_connection& socket) const;
        bool operator==(const data_connection& socket) const;
        bool operator!=(const data_connection& socket) const;

        protocol_t& protocol() const; // access underlying protocol

        unsigned last_specific_error();
    private:
        data_connection(const data_connection<PROTOCOL, ADDRESS>&);
        data_connection<PROTOCOL, ADDRESS>& operator=(const data_connection<PROTOCOL, ADDRESS>&);

        protocol_t           m_protocol;
    };

PROTOCOL would be an protocol policy class like:

   struct tcp : public socket_base
   {
   defines and things describing what options and what type of protocol tcp is
   these should be used as conceptual checks if protocol can be used with certain address types 
   and connectors and acceptors.

   typedef TYPELIST<ip_end_point> address_type_tl; 
   typedef TYPELIST<....> supported_options_tl;
   };

This is rather sketchy but can be worked out more closely if the ideas are liked.


BOOST WIKI | BoostSocket | RecentChanges | Preferences | Page List | Links List
Edit text of this page | View other revisions
Last edited December 18, 2004 12:30 pm (diff)
Search:
Disclaimer: This site not officially maintained by Boost Developers