#ifndef INCLUDED_BOBCAT_LOCALSOCKETBASE_
#define INCLUDED_BOBCAT_LOCALSOCKETBASE_

#include <sys/un.h>
#include <string>
#include <sys/socket.h>

#include <bobcat/exception>

namespace FBB
{

class LocalSocketBase
{
    size_t              d_length;
    int                 d_socket;
    struct sockaddr_un  d_address;

    protected:
        LocalSocketBase();                                      // 1
        explicit LocalSocketBase(std::string const &name);      // 1.f

        void open(std::string const &name);
        int socket() const;                                     // .f
        size_t size() const;                                    // .f
        sockaddr const *sockaddrPtr() const;                    // .f
};

inline LocalSocketBase::LocalSocketBase(std::string const &name)
{
    open(name);
}

inline size_t LocalSocketBase::size() const
{
    return d_length;
}
inline sockaddr const *LocalSocketBase::sockaddrPtr() const
{
    return reinterpret_cast<sockaddr const *>(&d_address);
}
inline int LocalSocketBase::socket() const
{
    return d_socket;
}

} // FBB

#endif
