Changeset

6536:605a87e90e27

net.cqueues: Add workaround for luaevent callback getting collected
author daurnimator <quae@daurnimator.com>
date Tue, 06 Jan 2015 20:01:59 -0500
parents 6535:0f940a7ba489
children 6537:e4d443d05626
files net/cqueues.lua
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/net/cqueues.lua	Tue Jan 06 19:33:25 2015 +0000
+++ b/net/cqueues.lua	Tue Jan 06 20:01:59 2015 -0500
@@ -43,7 +43,11 @@
 	cq = cqueues.new();
 	-- Only need to listen for readable; cqueues handles everything under the hood
 	local EV_READ = server.event.EV_READ;
-	server.base:addevent(cq:pollfd(), EV_READ, function(e)
+	local event_handle;
+	event_handle = server.base:addevent(cq:pollfd(), EV_READ, function(e)
+			-- Need to reference event_handle or this callback will get collected
+			-- This creates a circular reference that can only be broken if event_handle is manually :close()'d
+			local _ = event_handle;
 			assert(cq:loop(0));
 			-- Convert a cq timeout to an acceptable timeout for luaevent
 			local t = cq:timeout();