aboutsummaryrefslogtreecommitdiff
path: root/src/lua/net/Socket.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/net/Socket.h')
-rw-r--r--src/lua/net/Socket.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/lua/net/Socket.h b/src/lua/net/Socket.h
new file mode 100644
index 0000000..5834092
--- /dev/null
+++ b/src/lua/net/Socket.h
@@ -0,0 +1,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() {}
+
+ Socket(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()
+ {
+ delete socket;
+ }
+
+ };
+
+} // net
+} // lua
+} // jin
+
+#endif \ No newline at end of file