MEDIUM: lua: socket: add "socket" class for TCP I/O
This patch adds the TCP I/O functionnality. The class implemented
provides the same functions than the "lua socket" project. This
make network compatibility with another LUA project. The documentation
is located here:
http://w3.impa.br/~diego/software/luasocket/tcp.html
diff --git a/include/types/hlua.h b/include/types/hlua.h
index f21f4e1..4925155 100644
--- a/include/types/hlua.h
+++ b/include/types/hlua.h
@@ -2,9 +2,14 @@
#define _TYPES_HLUA_H
#include <lua.h>
+#include <lauxlib.h>
+
+#include <types/proxy.h>
+#include <types/server.h>
#define CLASS_CORE "Core"
#define CLASS_TXN "TXN"
+#define CLASS_SOCKET "Socket"
struct session;
@@ -100,4 +105,12 @@
unsigned int wakeup_ms; /* hour to wakeup. */
};
+/* This struct is used to create coprocess doing TCP or
+ * SSL I/O. It uses a fake session.
+ */
+struct hlua_socket {
+ struct session *s; /* Session used for socket I/O. */
+ luaL_Buffer b; /* buffer used to prepare strings. */
+};
+
#endif /* _TYPES_HLUA_H */
diff --git a/include/types/stream_interface.h b/include/types/stream_interface.h
index e060634..ab0e750 100644
--- a/include/types/stream_interface.h
+++ b/include/types/stream_interface.h
@@ -27,6 +27,9 @@
#include <types/channel.h>
#include <types/connection.h>
+#ifdef USE_LUA
+#include <types/hlua.h>
+#endif
#include <types/obj_type.h>
#include <common/config.h>
@@ -150,6 +153,14 @@
struct pattern_expr *expr;
struct chunk chunk;
} map;
+#ifdef USE_LUA
+ struct {
+ int connected;
+ struct hlua_socket *socket;
+ struct list wake_on_read;
+ struct list wake_on_write;
+ } hlua;
+#endif
} ctx; /* used by stats I/O handlers to dump the stats */
};