#pragma once

#include "Socket.h"

#include <string>
#include <functional>

class BerkeleySocket : public Socket
{
public:
    BerkeleySocket(const std::string& address, unsigned port);

    BerkeleySocket(int handle);

    ~BerkeleySocket();

    std::string recieve() override;

    void respond(const std::string& message) override;

    std::string send(const std::string& message) override;

    using onIncomingConnectionFunc = std::function<void(int)>;
    void doListen(onIncomingConnectionFunc connectionFunc);

private:
    void initialize() override;
    void initializeForBind() override;

    void doConnect() override;

    void doBind() override;

    void onSockerError(const std::string& message);

    int mHandle{ 0 };
};
