diff options
Diffstat (limited to 'src/libjin/Net')
-rw-r--r-- | src/libjin/Net/Net.cpp | 24 | ||||
-rw-r--r-- | src/libjin/Net/Net.h | 30 | ||||
-rw-r--r-- | src/libjin/Net/Socket.cpp | 190 | ||||
-rw-r--r-- | src/libjin/Net/Socket.h | 62 | ||||
-rw-r--r-- | src/libjin/Net/je_net_manager.cpp | 24 | ||||
-rw-r--r-- | src/libjin/Net/je_net_manager.h | 50 | ||||
-rw-r--r-- | src/libjin/Net/je_socket.cpp | 190 | ||||
-rw-r--r-- | src/libjin/Net/je_socket.h | 144 | ||||
-rw-r--r-- | src/libjin/Net/net.cpp | 24 | ||||
-rw-r--r-- | src/libjin/Net/net.h | 30 |
10 files changed, 408 insertions, 360 deletions
diff --git a/src/libjin/Net/Net.cpp b/src/libjin/Net/Net.cpp deleted file mode 100644 index db39be7..0000000 --- a/src/libjin/Net/Net.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "Net.h" - -namespace jin -{ -namespace net -{ - - bool Net::initSystem(const SettingBase* setting) - { - #ifdef _WIN32 - #if JIN_NET_TEKCOS - tk_init(); - #endif - #endif - return true; - } - - void Net::quitSystem() - { - - } - -} -} diff --git a/src/libjin/Net/Net.h b/src/libjin/Net/Net.h deleted file mode 100644 index 54ffede..0000000 --- a/src/libjin/Net/Net.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __JIN_NET_H -#define __JIN_NET_H -#include "../modules.h" -#if JIN_MODULES_NET - -#include "../Common/Subsystem.hpp" -#include "Socket.h" - -namespace jin -{ -namespace net -{ - - class Net : public Subsystem<Net> - { - public: - - protected: - Net() {}; - ~Net() {}; - SINGLETON(Net); - bool initSystem(const SettingBase* setting) override; - void quitSystem() override; - }; - -} -} - -#endif // JIN_MODULES_NET -#endif // __JIN_NET_H
\ No newline at end of file diff --git a/src/libjin/Net/Socket.cpp b/src/libjin/Net/Socket.cpp deleted file mode 100644 index cfc593a..0000000 --- a/src/libjin/Net/Socket.cpp +++ /dev/null @@ -1,190 +0,0 @@ -#include "Socket.h" - -namespace jin -{ -namespace net -{ - Socket::Socket(const Socket& socket) - : handle(socket.handle) - , type(socket.type) - { - } - - Socket::Socket(const SocketInformation& info) - : type(info.type) - { - if (type == SocketType::TCP) - { - tk_IPaddress ip; - ip.host = info.address; - ip.port = info.port; - handle.tcpHandle = tk_tcp_open(ip); - } - else if (type == SocketType::UDP) - { - handle.udpHandle = tk_udp_open(info.port); - } - } - - Socket::Socket(SocketType type, const char* address, unsigned short port) - { - this->type = type; - if (type == SocketType::TCP) - { - tk_IPaddress ip; - #if JIN_NET_TEKCOS - ip.host = tk_strtohl(address); - ip.port = port; - handle.tcpHandle = tk_tcp_open(ip); - #endif - } - else if (type == SocketType::UDP) - { - handle.udpHandle = tk_udp_open(port); - } - } - - Socket::Socket(SocketType type, unsigned int address, unsigned short port) - { - this->type = type; - if (type == SocketType::TCP) - { - tk_IPaddress ip; - ip.host = address; - ip.port = port; - handle.tcpHandle = tk_tcp_open(ip); - } - else if (type == SocketType::UDP) - { - handle.udpHandle = tk_udp_open(port); - } - } - - Socket::Socket(SocketType type, unsigned short port) - { - this->type = type; - if (type == SocketType::TCP) - { - tk_IPaddress ip; - ip.host = 0; - ip.port = port; - handle.tcpHandle = tk_tcp_open(ip); - } - else if (type == SocketType::UDP) - { - handle.udpHandle = tk_udp_open(port); - } - } - -#if JIN_NET_TEKCOS - - Socket::Socket(const tk_TCPsocket& tcphandle) - { - handle.tcpHandle = tcphandle; - } - - Socket::Socket(const tk_UDPsocket& udphandle) - { - handle.udpHandle = udphandle; - } - -#endif // JIN_NET_TEKCOS - - Socket::~Socket() - { - } - - void Socket::configureBlocking(bool blocking) - { - if (type != SocketType::TCP) - return; - #if JIN_NET_TEKCOS - if (blocking) - tk_tcp_blocking(&handle.tcpHandle); - else - tk_tcp_nonblocking(&handle.tcpHandle); - #endif - } - - Socket* Socket::accept() - { - if (type != SocketType::TCP) - return nullptr; - Socket* client; - #if JIN_NET_TEKCOS - tk_TCPsocket socket = tk_tcp_accept(&handle.tcpHandle); - client = new Socket(socket); - #endif - return client; - } - - int Socket::receive(char* buffer, int size) - { - if (type != SocketType::TCP) - return 0; - #if JIN_NET_TEKCOS - int len; - tk_tcp_recv(&handle.tcpHandle, buffer, size, &len); - return len; - #endif - } - - int Socket::send(char* buffer, int size) - { - if (type != SocketType::TCP) - return 0; - #if JIN_NET_TEKCOS - int len; - tk_tcp_send(&handle.tcpHandle, buffer, size, &len); - return len; - #endif - } - - void Socket::sendTo(char* buffer, int size, unsigned int address, unsigned int port) - { - if (type != SocketType::UDP) - return; - #if JIN_NET_TEKCOS - tk_UDPpack pack; - pack.data = buffer; - pack.len = size; - pack.ip.host = address; - pack.ip.port = port; - tk_udp_sendto(&handle.udpHandle, &pack); - #endif - } - - int Socket::receiveFrom(char* buffer, int size, unsigned int address, unsigned int port) - { - if (type != SocketType::UDP) - return 0; - int len; - #if JIN_NET_TEKCOS - tk_UDPpack pack; - pack.data = buffer; - pack.len = size; - pack.ip.host = address; - pack.ip.port = port; - tk_udp_recvfrom(&handle.udpHandle, &pack); - return pack.len; - #endif - } - - void Socket::close() - { - if (type == SocketType::TCP) - { - #if JIN_NET_TEKCOS - tk_tcp_close(&handle.tcpHandle); - #endif - } - else if (type == SocketType::UDP) - { - #if JIN_NET_TEKCOS - tk_udp_close(&handle.udpHandle); - #endif - } - } - -} -}
\ No newline at end of file diff --git a/src/libjin/Net/Socket.h b/src/libjin/Net/Socket.h deleted file mode 100644 index 6d9e09b..0000000 --- a/src/libjin/Net/Socket.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef __JIN_NET_SOCKET_H -#define __JIN_NET_SOCKET_H -#include "../modules.h" -#if JIN_MODULES_NET - -#include "../3rdparty/tekcos/tekcos.h" - -namespace jin -{ -namespace net -{ - - enum SocketType - { - TCP, - UDP - }; - - struct SocketInformation - { - unsigned int address; - unsigned short port; - SocketType type; - }; - - class Socket - { - public: - Socket() {}; - Socket(const Socket& socket); - Socket(const SocketInformation& socketInformation); - Socket(SocketType type, unsigned short port); - Socket(SocketType type, unsigned int address, unsigned short port); - Socket(SocketType type, const char* address, unsigned short port); - ~Socket(); - - void configureBlocking(bool bocking); - Socket* accept(); - int receive(char* buffer, int size); - int send(char* buffer, int size); - void sendTo(char* buffer, int size, unsigned int address, unsigned int port); - int receiveFrom(char* buffer, int size, unsigned int address, unsigned int port); - void close(); - - protected: - #if JIN_NET_TEKCOS - Socket(const tk_TCPsocket& tcpHandle); - Socket(const tk_UDPsocket& udpHandle); - union - { - tk_TCPsocket tcpHandle; - tk_UDPsocket udpHandle; - } handle; - #endif - SocketType type; - }; - -} // net -} // jin - -#endif // JIN_MODULES_NET -#endif // __JIN_NET_SOCKET_H
\ No newline at end of file diff --git a/src/libjin/Net/je_net_manager.cpp b/src/libjin/Net/je_net_manager.cpp new file mode 100644 index 0000000..c4f822e --- /dev/null +++ b/src/libjin/Net/je_net_manager.cpp @@ -0,0 +1,24 @@ +#include "je_net_manager.h" + +namespace JinEngine +{ + namespace Net + { + + bool NetManager::initSystem(const SettingBase* setting) + { + #ifdef _WIN32 + #if jin_net == jin_net_tekcos + tk_init(); + #endif + #endif + return true; + } + + void NetManager::quitSystem() + { + + } + + } // namespace Net +} // namespace JinEngine
\ No newline at end of file diff --git a/src/libjin/Net/je_net_manager.h b/src/libjin/Net/je_net_manager.h new file mode 100644 index 0000000..8f72b73 --- /dev/null +++ b/src/libjin/Net/je_net_manager.h @@ -0,0 +1,50 @@ +#ifndef __JE_NET_H +#define __JE_NET_H +#include "../core/je_configuration.h" +#if defined(jin_net) + +#include "../common/je_subsystem.hpp" + +#include "je_socket.h" + +namespace JinEngine +{ + namespace Net + { + + /// + /// + /// + class NetManager : public Subsystem<NetManager> + { + protected: + singleton(NetManager); + + /// + /// + /// + NetManager() {}; + + /// + /// + /// + ~NetManager() {}; + + /// + /// + /// + bool initSystem(const SettingBase* setting) override; + + /// + /// + /// + void quitSystem() override; + + }; + + } // namespace Net +} // namespace JinEngine + +#endif // defined(jin_net) + +#endif // __JE_NET_H
\ No newline at end of file diff --git a/src/libjin/Net/je_socket.cpp b/src/libjin/Net/je_socket.cpp new file mode 100644 index 0000000..1810601 --- /dev/null +++ b/src/libjin/Net/je_socket.cpp @@ -0,0 +1,190 @@ +#include "je_socket.h" + +namespace JinEngine +{ + namespace Net + { + Socket::Socket(const Socket& socket) + : mHandle(socket.mHandle) + , mType(socket.mType) + { + } + + Socket::Socket(const SocketInformation& info) + : mType(info.type) + { + if (mType == SocketType::TCP) + { + tk_IPaddress ip; + ip.host = info.address; + ip.port = info.port; + mHandle.tcpHandle = tk_tcp_open(ip); + } + else if (mType == SocketType::UDP) + { + mHandle.udpHandle = tk_udp_open(info.port); + } + } + + Socket::Socket(SocketType type, const char* address, unsigned short port) + { + mType = type; + if (mType == SocketType::TCP) + { + tk_IPaddress ip; + #if jin_net == jin_net_tekcos + ip.host = tk_strtohl(address); + ip.port = port; + mHandle.tcpHandle = tk_tcp_open(ip); + #endif + } + else if (mType == SocketType::UDP) + { + mHandle.udpHandle = tk_udp_open(port); + } + } + + Socket::Socket(SocketType type, unsigned int address, unsigned short port) + { + mType = type; + if (mType == SocketType::TCP) + { + tk_IPaddress ip; + ip.host = address; + ip.port = port; + mHandle.tcpHandle = tk_tcp_open(ip); + } + else if (mType == SocketType::UDP) + { + mHandle.udpHandle = tk_udp_open(port); + } + } + + Socket::Socket(SocketType type, unsigned short port) + { + mType = type; + if (mType == SocketType::TCP) + { + tk_IPaddress ip; + ip.host = 0; + ip.port = port; + mHandle.tcpHandle = tk_tcp_open(ip); + } + else if (mType == SocketType::UDP) + { + mHandle.udpHandle = tk_udp_open(port); + } + } + + #if jin_net == jin_net_tekcos + + Socket::Socket(const tk_TCPsocket& tcphandle) + { + mHandle.tcpHandle = tcphandle; + } + + Socket::Socket(const tk_UDPsocket& udphandle) + { + mHandle.udpHandle = udphandle; + } + + #endif // jin_net == jin_net_tekcos + + Socket::~Socket() + { + } + + void Socket::configureBlocking(bool blocking) + { + if (mType != SocketType::TCP) + return; + #if jin_net == jin_net_tekcos + if (blocking) + tk_tcp_blocking(&mHandle.tcpHandle); + else + tk_tcp_nonblocking(&mHandle.tcpHandle); + #endif + } + + Socket* Socket::accept() + { + if (mType != SocketType::TCP) + return nullptr; + Socket* client; + #if jin_net == jin_net_tekcos + tk_TCPsocket socket = tk_tcp_accept(&mHandle.tcpHandle); + client = new Socket(socket); + #endif + return client; + } + + int Socket::receive(char* buffer, int size) + { + if (mType != SocketType::TCP) + return 0; + #if jin_net == jin_net_tekcos + int len; + tk_tcp_recv(&mHandle.tcpHandle, buffer, size, &len); + return len; + #endif + } + + int Socket::send(char* buffer, int size) + { + if (mType != SocketType::TCP) + return 0; + #if jin_net == jin_net_tekcos + int len; + tk_tcp_send(&mHandle.tcpHandle, buffer, size, &len); + return len; + #endif + } + + void Socket::sendTo(char* buffer, int size, unsigned int address, unsigned int port) + { + if (mType != SocketType::UDP) + return; + #if jin_net == jin_net_tekcos + tk_UDPpack pack; + pack.data = buffer; + pack.len = size; + pack.ip.host = address; + pack.ip.port = port; + tk_udp_sendto(&mHandle.udpHandle, &pack); + #endif + } + + int Socket::receiveFrom(char* buffer, int size, unsigned int address, unsigned int port) + { + if (mType != SocketType::UDP) + return 0; + int len; + #if jin_net == jin_net_tekcos + tk_UDPpack pack; + pack.data = buffer; + pack.len = size; + pack.ip.host = address; + pack.ip.port = port; + tk_udp_recvfrom(&mHandle.udpHandle, &pack); + return pack.len; + #endif + } + + void Socket::close() + { + if (mType == SocketType::TCP) + { + #if jin_net == jin_net_tekcos + tk_tcp_close(&mHandle.tcpHandle); + #endif + } + else if (mType == SocketType::UDP) + { + #if jin_net == jin_net_tekcos + tk_udp_close(&mHandle.udpHandle); + #endif + } + } + + } // namespace Net +} // namespace JinEngine
\ No newline at end of file diff --git a/src/libjin/Net/je_socket.h b/src/libjin/Net/je_socket.h new file mode 100644 index 0000000..d496fcb --- /dev/null +++ b/src/libjin/Net/je_socket.h @@ -0,0 +1,144 @@ +#ifndef __JE_NET_SOCKET_H +#define __JE_NET_SOCKET_H +#include "../core/je_configuration.h" +#if defined(jin_net) + +#include "../3rdparty/tekcos/tekcos.h" + +namespace JinEngine +{ + namespace Net + { + + /// + /// + /// + enum SocketType + { + TCP, + UDP + }; + + /// + /// + /// + struct SocketInformation + { + unsigned int address; + unsigned short port; + SocketType type; + }; + + /// + /// + /// + class Socket + { + public: + + /// + /// + /// + Socket() {}; + + /// + /// + /// + Socket(const Socket& socket); + + /// + /// + /// + Socket(const SocketInformation& socketInformation); + + /// + /// + /// + Socket(SocketType type, unsigned short port); + + /// + /// + /// + Socket(SocketType type, unsigned int address, unsigned short port); + + /// + /// + /// + Socket(SocketType type, const char* address, unsigned short port); + + /// + /// + /// + ~Socket(); + + /// + /// + /// + void configureBlocking(bool bocking); + + /// + /// + /// + Socket* accept(); + + /// + /// + /// + int receive(char* buffer, int size); + + /// + /// + /// + int send(char* buffer, int size); + + /// + /// + /// + void sendTo(char* buffer, int size, unsigned int address, unsigned int port); + + /// + /// + /// + int receiveFrom(char* buffer, int size, unsigned int address, unsigned int port); + + /// + /// + /// + void close(); + + protected: + #if jin_net == jin_net_tekcos + + /// + /// + /// + Socket(const tk_TCPsocket& tcpHandle); + + /// + /// + /// + Socket(const tk_UDPsocket& udpHandle); + + /// + /// + /// + union + { + tk_TCPsocket tcpHandle; + tk_UDPsocket udpHandle; + } mHandle; + #endif + + /// + /// + /// + SocketType mType; + + }; + + } // namespace Net +} // namespace JinEngine + +#endif // defined(jin_net) + +#endif // __JE_NET_SOCKET_H
\ No newline at end of file diff --git a/src/libjin/Net/net.cpp b/src/libjin/Net/net.cpp deleted file mode 100644 index db39be7..0000000 --- a/src/libjin/Net/net.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "Net.h" - -namespace jin -{ -namespace net -{ - - bool Net::initSystem(const SettingBase* setting) - { - #ifdef _WIN32 - #if JIN_NET_TEKCOS - tk_init(); - #endif - #endif - return true; - } - - void Net::quitSystem() - { - - } - -} -} diff --git a/src/libjin/Net/net.h b/src/libjin/Net/net.h deleted file mode 100644 index 54ffede..0000000 --- a/src/libjin/Net/net.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __JIN_NET_H -#define __JIN_NET_H -#include "../modules.h" -#if JIN_MODULES_NET - -#include "../Common/Subsystem.hpp" -#include "Socket.h" - -namespace jin -{ -namespace net -{ - - class Net : public Subsystem<Net> - { - public: - - protected: - Net() {}; - ~Net() {}; - SINGLETON(Net); - bool initSystem(const SettingBase* setting) override; - void quitSystem() override; - }; - -} -} - -#endif // JIN_MODULES_NET -#endif // __JIN_NET_H
\ No newline at end of file |