MINOR: lua: adds "forced yield" flag

This flag indicate that the current yield is returned by the Lua
execution task control. If this flag is set, the current task may
quit but will be set in the run queue to be re-executed immediatly.

This patch modify the "hlua_yieldk()" function, it adds an argument
that contain a field containing yield options.
diff --git a/include/proto/hlua.h b/include/proto/hlua.h
index 1428673..c3235da 100644
--- a/include/proto/hlua.h
+++ b/include/proto/hlua.h
@@ -11,6 +11,9 @@
 #define HLUA_SET_RUN(__hlua)         do {(__hlua)->flags |= HLUA_RUN;} while(0)
 #define HLUA_CLR_RUN(__hlua)         do {(__hlua)->flags &= ~HLUA_RUN;} while(0)
 #define HLUA_IS_RUNNING(__hlua)      ((__hlua)->flags & HLUA_RUN)
+#define HLUA_SET_CTRLYIELD(__hlua)   do {(__hlua)->flags |= HLUA_CTRLYIELD;} while(0)
+#define HLUA_CLR_CTRLYIELD(__hlua)   do {(__hlua)->flags &= ~HLUA_CTRLYIELD;} while(0)
+#define HLUA_IS_CTRLYIELDING(__hlua) ((__hlua)->flags & HLUA_CTRLYIELD)
 
 #define HLUA_INIT(__hlua) do { (__hlua)->T = 0; } while(0)
 
diff --git a/include/types/hlua.h b/include/types/hlua.h
index 0e1b2fc..58402f4 100644
--- a/include/types/hlua.h
+++ b/include/types/hlua.h
@@ -17,6 +17,7 @@
 struct session;
 
 #define HLUA_RUN       0x00000001
+#define HLUA_CTRLYIELD 0x00000002
 
 enum hlua_exec {
 	HLUA_E_OK = 0,
diff --git a/src/hlua.c b/src/hlua.c
index 8f8f0bd..ef55922 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -513,7 +513,7 @@
  * returned with a timeout and permit to set some flags
  */
 __LJMP void hlua_yieldk(lua_State *L, int nresults, int ctx,
-                        lua_CFunction k, int timeout)
+                        lua_CFunction k, int timeout, unsigned int flags)
 {
 	struct hlua *hlua = hlua_gethlua(L);
 
@@ -524,6 +524,8 @@
 	if (hlua->wake_time == TICK_ETERNITY)
 		hlua->wake_time = hlua->expire;
 
+	hlua->flags |= flags;
+
 	/* Process the yield. */
 	WILL_LJMP(lua_yieldk(L, nresults, ctx, k));
 }
@@ -1156,7 +1158,7 @@
 	appctx = objt_appctx(socket->s->si[0].end);
 	if (!hlua_com_new(hlua, &appctx->ctx.hlua.wake_on_read))
 		WILL_LJMP(luaL_error(L, "out of memory"));
-	WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_receive_yield, TICK_ETERNITY));
+	WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_receive_yield, TICK_ETERNITY, 0));
 	return 0;
 }
 
@@ -1306,7 +1308,7 @@
 	appctx = objt_appctx(socket->s->si[0].end);
 	if (!hlua_com_new(hlua, &appctx->ctx.hlua.wake_on_write))
 		WILL_LJMP(luaL_error(L, "out of memory"));
-	WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_write_yield, TICK_ETERNITY));
+	WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_write_yield, TICK_ETERNITY, 0));
 	return 0;
 }
 
@@ -1536,7 +1538,7 @@
 
 	if (!hlua_com_new(hlua, &appctx->ctx.hlua.wake_on_write))
 		WILL_LJMP(luaL_error(L, "out of memory error"));
-	WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_connect_yield, TICK_ETERNITY));
+	WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_connect_yield, TICK_ETERNITY, 0));
 	return 0;
 }
 
@@ -1576,7 +1578,7 @@
 	 */
 	task_wakeup(socket->s->task, TASK_WOKEN_INIT);
 
-	WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_connect_yield, TICK_ETERNITY));
+	WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_connect_yield, TICK_ETERNITY, 0));
 
 	return 0;
 }
@@ -1961,7 +1963,7 @@
 	chn = MAY_LJMP(hlua_checkchannel(L, 1));
 
 	if (_hlua_channel_dup(chn, L) == 0)
-		WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_dup, TICK_ETERNITY));
+		WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_dup, TICK_ETERNITY, 0));
 	return 1;
 }
 
@@ -1980,7 +1982,7 @@
 	chn = MAY_LJMP(hlua_checkchannel(L, 1));
 	ret = _hlua_channel_dup(chn, L);
 	if (unlikely(ret == 0))
-		WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_get, TICK_ETERNITY));
+		WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_get, TICK_ETERNITY, 0));
 
 	if (unlikely(ret == -1))
 		return 1;
@@ -2010,7 +2012,7 @@
 
 	ret = bi_getline_nc(chn->chn, &blk1, &len1, &blk2, &len2);
 	if (ret == 0)
-		WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_getline, TICK_ETERNITY));
+		WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_getline, TICK_ETERNITY, 0));
 
 	if (ret == -1) {
 		lua_pushnil(L);
@@ -2055,7 +2057,7 @@
 		return 1;
 	}
 	if (ret == -1)
-		WILL_LJMP(hlua_yieldk(L, 0, 0, _hlua_channel_append, TICK_ETERNITY));
+		WILL_LJMP(hlua_yieldk(L, 0, 0, _hlua_channel_append, TICK_ETERNITY, 0));
 	l += ret;
 	lua_pop(L, 1);
 	lua_pushinteger(L, l);
@@ -2069,7 +2071,7 @@
 		return 1;
 	}
 	if (l < len)
-		WILL_LJMP(hlua_yieldk(L, 0, 0, _hlua_channel_append, TICK_ETERNITY));
+		WILL_LJMP(hlua_yieldk(L, 0, 0, _hlua_channel_append, TICK_ETERNITY, 0));
 	return 1;
 }
 
@@ -2145,7 +2147,7 @@
 		return 1;
 	}
 	if (l < len)
-		WILL_LJMP(hlua_yieldk(L, 0, 0, _hlua_channel_send, TICK_ETERNITY));
+		WILL_LJMP(hlua_yieldk(L, 0, 0, _hlua_channel_send, TICK_ETERNITY, 0));
 
 	return 1;
 }
@@ -2198,7 +2200,7 @@
 			return 1;
 
 		/* Otherwise, we can yield waiting for new data in the inpout side. */
-		WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_forward_yield, TICK_ETERNITY));
+		WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_forward_yield, TICK_ETERNITY, 0));
 	}
 
 	return 1;
@@ -2520,7 +2522,7 @@
 {
 	int wakeup_ms = lua_tointeger(L, -1);
 	if (now_ms < wakeup_ms)
-		WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, TICK_ETERNITY));
+		WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, TICK_ETERNITY, 0));
 	return 0;
 }
 
@@ -2559,7 +2561,7 @@
 	/* Store the wakeup time in the lua stack. */
 	lua_pushinteger(L, t->wakeup_ms);
 
-	WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, TICK_ETERNITY));
+	WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, TICK_ETERNITY, 0));
 	return 0;
 }