diff options
author | chai <chaifix@163.com> | 2018-08-14 14:56:47 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-08-14 14:56:47 +0800 |
commit | 5c9af043503f92852a1a765b6ecfbc1aea24d2e9 (patch) | |
tree | eb371092c4137a672e7bfc13dc56ee777623ebfe /src/lua/net/Socket.h | |
parent | 5162f84be0a4deb447c6ba1226722b049335d525 (diff) |
*update
Diffstat (limited to 'src/lua/net/Socket.h')
-rw-r--r-- | src/lua/net/Socket.h | 77 |
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 |