#ifndef _INCLUDED_BOBCAT_SOCKETBASE_
#define _INCLUDED_BOBCAT_SOCKETBASE_

#include <bobcat/inetaddress>
#include <string>
#include <sys/socket.h>

/*
    int info coming in/going out: host byte order
*/

namespace FBB
{
    class SocketBase: public InetAddress
    {
        int         d_sock;

        public:
            bool debug() const throw(Errno)
            {
                return boolOption(SO_DEBUG);
            }

            bool reuse() const throw(Errno)
            {
                return boolOption(SO_REUSEADDR);
            }

            int socket() const
            {
                return d_sock;
            }


            bool setDebug(bool trueIsOn) throw (Errno)
            {
                return setBoolOption(SO_DEBUG, trueIsOn);
            }

            bool setReuse(bool trueIsOn) throw (Errno)
            {
                return setBoolOption(SO_REUSEADDR, trueIsOn);
            }

        protected:
            SocketBase(uint16_t port) throw (Errno);            // 1
            SocketBase(std::string const &host, uint16_t port) throw (Errno);
                                                                // 2
            SocketBase(int socket, sockaddr_in const &address)
            :
                InetAddress(address),
                d_sock(socket)
            {}

        private:
            bool boolOption(int optname) const throw (Errno);
            bool setBoolOption(int optname, bool newValue) throw (Errno);
    };
}

#endif



