about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-07-18 00:18:50 +0000
committerEric Wong <e@80x24.org>2014-07-18 00:29:25 +0000
commit3c56a143fe2ef00716b89dd2f115cf8ea24a7d8c (patch)
treecf01a51781b2e466e0adbf6557ede87f85b138e9 /lib
parentdef5f784b5a26a3f698a93f3b6b63946a09e7c44 (diff)
downloadyahns-3c56a143fe2ef00716b89dd2f115cf8ea24a7d8c.tar.gz
We should no longer need HTTP parser or input body upon hijacking.
Remove references to it so the GC can clean those up.  This relies
on the Rack application deleting "rack.input" from the Rack env,
too.
Diffstat (limited to 'lib')
-rw-r--r--lib/yahns/http_client.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/yahns/http_client.rb b/lib/yahns/http_client.rb
index 849095e..a294511 100644
--- a/lib/yahns/http_client.rb
+++ b/lib/yahns/http_client.rb
@@ -224,9 +224,10 @@ class Yahns::HttpClient < Kgio::Socket # :nodoc:
     http_response_write(status, headers, body)
   end
 
+  # this is the env["rack.hijack"] callback exposed to the Rack app
   def hijack_proc(env)
     proc do
-      self.class.queue.queue_del(self) # EPOLL_CTL_DEL
+      hijack_cleanup
       env[RACK_HIJACK_IO] = self
     end
   end
@@ -253,12 +254,19 @@ class Yahns::HttpClient < Kgio::Socket # :nodoc:
     end while true
   end
 
-  def response_hijacked(fn)
+  # allow releasing some memory if rack.hijack is used
+  def hijack_cleanup
     # we must issue EPOLL_CTL_DEL before hijacking (if we issue it at all),
     # because the hijacker may close use before we get back to the epoll worker
     # loop.  EPOLL_CTL_DEL saves about 200 bytes of unswappable kernel memory,
     # so it can matter if we have lots of hijacked sockets.
-    self.class.queue.queue_del(self)
+    self.class.queue.queue_del(self) # EPOLL_CTL_DEL
+    @input = @input.close if @input
+    @hs = nil # no need for the HTTP parser anymore
+  end
+
+  def response_hijacked(fn)
+    hijack_cleanup
     fn.call(self)
     :ignore
   end