aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/net/socket.h
blob: 4a65245d1f7fd47c297f30864428f346167c400b (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef __JE_NET_SOCKET_H__
#define __JE_NET_SOCKET_H__
#include "../core/configuration.h"
#if defined(jin_net)

#include "../common/object.h"

#include "tekcos/tekcos.h"

namespace JinEngine
{
	namespace Net
	{

		///
		///
		///
		enum SocketType
		{
			TCP,
			UDP
		};

		///
		///
		///
		struct SocketInformation
		{
			unsigned int address;
			unsigned short port;
			SocketType type;
		};

		///
		///
		///
		class Socket : public Object
		{
		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__