aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Net/Socket.h
blob: dfc1e416a7a31ba08d48adf67d471f7f819c62fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef __LIBJIN_NET_SOCKET_H
#define __LIBJIN_NET_SOCKET_H
#include "../jin_configuration.h"
#if LIBJIN_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 LIBJIN_NET_TEKCOS
			Socket(const tk_TCPsocket& tcpHandle);
			Socket(const tk_UDPsocket& udpHandle);
			union
			{
				tk_TCPsocket tcpHandle;
				tk_UDPsocket udpHandle;
			} handle;
		#endif
			SocketType type;

		};

	} // namespace net 
} // namespace jin 

#endif // LIBJIN_MODULES_NET
#endif // __LIBJIN_NET_SOCKET_H