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
|
#ifndef __JIN_LUA_NET_SOCKET_H
#define __JIN_LUA_NET_SOCKET_H
#include "libjin/jin.h"
#include "../luaopen_types.h"
namespace jin
{
namespace lua
{
namespace net
{
typedef jin::net::SocketInformation SocketInformation;
typedef jin::net::SocketType SocketType;
class Socket : public Object
{
public:
Socket(const SocketInformation& info)
{
socket = new jin::net::Socket(info);
}
void configureBlocking(bool blocking)
{
socket->configureBlocking(blocking);
}
Socket* accept()
{
Socket* client = new Socket();
client->socket = socket->accept();
return client;
}
int receive(char* buffer, int size)
{
return socket->receive(buffer, size);
}
int send(char* buffer, int size)
{
return socket->send(buffer, size);
}
void sendTo(char* buffer, int size, unsigned int address, unsigned int port)
{
socket->sendTo(buffer, size, address, port);
}
int receiveFrom(char* buffer, int size, unsigned int address, unsigned int port)
{
return socket->receiveFrom(buffer, size, address, port);
}
void close()
{
socket->close();
}
private:
jin::net::Socket* socket;
Socket() {}
~Socket()
{
delete socket;
}
};
} // net
} // lua
} // jin
#endif
|