From 4ec243dfc2220df603396a78f67e86c16f9db8f7 Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Mon, 4 Jun 2018 16:46:29 +0200 Subject: Moved files --- include/DirectConnection.hpp | 83 --------------------------------------- include/sibs/DirectConnection.hpp | 83 +++++++++++++++++++++++++++++++++++++++ src/DirectConnection.cpp | 2 +- 3 files changed, 84 insertions(+), 84 deletions(-) delete mode 100644 include/DirectConnection.hpp create mode 100644 include/sibs/DirectConnection.hpp diff --git a/include/DirectConnection.hpp b/include/DirectConnection.hpp deleted file mode 100644 index 4075d12..0000000 --- a/include/DirectConnection.hpp +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include "types.hpp" -#include "utils.hpp" - -struct addrinfo; - -namespace sibs -{ - class InvalidAddressException : public std::runtime_error - { - public: - InvalidAddressException(const std::string &errMsg) : std::runtime_error(errMsg) {} - }; - - class ConnectionException : public std::runtime_error - { - public: - ConnectionException(const std::string &errMsg) : std::runtime_error(errMsg) {} - }; - - class SendException : public std::runtime_error - { - public: - SendException(const std::string &errMsg) : std::runtime_error(errMsg) {} - }; - - class Ipv4 - { - DISABLE_COPY(Ipv4) - public: - // Throws InvalidAddressException on error - Ipv4(const char *ip, u16 port); - ~Ipv4(); - - struct addrinfo *address; - }; - - enum class PubSubConnectResult - { - OK, - ERROR - }; - - using PubSubConnectCallback = std::function; - using PubSubReceiveDataCallback = std::function; - - struct DirectConnectionPeer - { - int socket; - PubSubReceiveDataCallback receiveDataCallbackFunc; - }; - - class DirectConnections - { - DISABLE_COPY(DirectConnections) - public: - DirectConnections(u16 port = 27137); - ~DirectConnections(); - - // Throws ConnectionException on error - std::shared_ptr connect(const Ipv4 &address, PubSubReceiveDataCallback receiveDataCallbackFunc); - // Throws SendException on error - void send(const std::shared_ptr &peer, const void *data, const usize size); - private: - void receiveData(); - bool receiveDataFromPeer(const int socket, char *output); - private: - u16 port; - int eid; - std::unordered_map> peers; - std::thread receiveDataThread; - std::mutex peersMutex; - bool alive; - }; -} diff --git a/include/sibs/DirectConnection.hpp b/include/sibs/DirectConnection.hpp new file mode 100644 index 0000000..8e92137 --- /dev/null +++ b/include/sibs/DirectConnection.hpp @@ -0,0 +1,83 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include "../types.hpp" +#include "../utils.hpp" + +struct addrinfo; + +namespace sibs +{ + class InvalidAddressException : public std::runtime_error + { + public: + InvalidAddressException(const std::string &errMsg) : std::runtime_error(errMsg) {} + }; + + class ConnectionException : public std::runtime_error + { + public: + ConnectionException(const std::string &errMsg) : std::runtime_error(errMsg) {} + }; + + class SendException : public std::runtime_error + { + public: + SendException(const std::string &errMsg) : std::runtime_error(errMsg) {} + }; + + class Ipv4 + { + DISABLE_COPY(Ipv4) + public: + // Throws InvalidAddressException on error + Ipv4(const char *ip, u16 port); + ~Ipv4(); + + struct addrinfo *address; + }; + + enum class PubSubConnectResult + { + OK, + ERROR + }; + + using PubSubConnectCallback = std::function; + using PubSubReceiveDataCallback = std::function; + + struct DirectConnectionPeer + { + int socket; + PubSubReceiveDataCallback receiveDataCallbackFunc; + }; + + class DirectConnections + { + DISABLE_COPY(DirectConnections) + public: + DirectConnections(u16 port = 27137); + ~DirectConnections(); + + // Throws ConnectionException on error + std::shared_ptr connect(const Ipv4 &address, PubSubReceiveDataCallback receiveDataCallbackFunc); + // Throws SendException on error + void send(const std::shared_ptr &peer, const void *data, const usize size); + private: + void receiveData(); + bool receiveDataFromPeer(const int socket, char *output); + private: + u16 port; + int eid; + std::unordered_map> peers; + std::thread receiveDataThread; + std::mutex peersMutex; + bool alive; + }; +} diff --git a/src/DirectConnection.cpp b/src/DirectConnection.cpp index 3e79658..6e3ddcc 100644 --- a/src/DirectConnection.cpp +++ b/src/DirectConnection.cpp @@ -1,4 +1,4 @@ -#include "../include/DirectConnection.hpp" +#include "../include/sibs/DirectConnection.hpp" #include "../include/Log.hpp" #include #include -- cgit v1.2.3