From aa7549126a4e821cecf75fbc32a433a7f8122d2b Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 8 Aug 2018 17:28:41 +0800 Subject: +network --- src/libjin/Net/Socket.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/libjin/Net/Socket.h (limited to 'src/libjin/Net/Socket.h') diff --git a/src/libjin/Net/Socket.h b/src/libjin/Net/Socket.h new file mode 100644 index 0000000..0eb27e0 --- /dev/null +++ b/src/libjin/Net/Socket.h @@ -0,0 +1,58 @@ +#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(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(); + + private: + #if JIN_NET_TEKCOS + Socket(tk_TCPsocket* tcpHandle); + Socket(tk_UDPsocket* udpHandle); + tk_TCPsocket* tcpHandle; + tk_UDPsocket* udpHandle; + #endif + SocketType type; + }; + +} // net +} // jin + +#endif // JIN_MODULES_NET +#endif // __JIN_NET_SOCKET_H \ No newline at end of file -- cgit v1.1-26-g67d0