[Groonga-commit] ranguba/gqtp at d3798ab [master] Add support for closing after shutdown/quit

アーカイブの一覧に戻る
Kouhei Sutou null+****@clear*****
Sat May 11 17:02:45 JST 2019


Kouhei Sutou	2019-05-11 17:02:45 +0900 (Sat, 11 May 2019)

  Revision: d3798abdd8108b99ff1b828b77d778d4a75c9f69
  https://github.com/ranguba/gqtp/commit/d3798abdd8108b99ff1b828b77d778d4a75c9f69

  Message:
    Add support for closing after shutdown/quit

  Modified files:
    lib/gqtp/client.rb

  Modified: lib/gqtp/client.rb (+17 -4)
===================================================================
--- lib/gqtp/client.rb    2015-05-28 22:21:27 +0900 (7f6ef0b)
+++ lib/gqtp/client.rb    2019-05-11 17:02:45 +0900 (fa10e97)
@@ -27,12 +27,20 @@ module GQTP
       @options[:host] ||= @options[:address] || "127.0.0.1"
       @options[:port] ||= 10043
       @backend = create_backend
+      @close_requesting = false
     end
 
     def send(body, options={}, &block)
       header = options[:header] || Header.new
       header.size = body.bytesize
 
+      case body
+      when /\A(?:shutdown|quit)(?:\z|\s)/
+        @close_requesting = true
+      when /\A\/d\/(?:shutdown|quit)(?:\z|\?)/
+        @close_requesting = true
+      end
+
       if block_given?
         sequential_request = SequentialRequest.new
         write_request =****@backe*****(header.pack, body) do
@@ -55,6 +63,10 @@ module GQTP
         parser << header
         read_body_request =****@backe*****(parser.header.size) do |body|
           response_body = body
+          if @close_requesting
+            @backend.close
+            @backend = nil
+          end
           yield(parser.header, response_body) if block_given?
         end
         sequential_request << read_body_request
@@ -87,11 +99,12 @@ module GQTP
     def close
       sync = !block_given?
       sequential_request = SequentialRequest.new
-      quit_request = send("quit", :header => header_for_close) do
-        @backend.close
-        yield if block_given?
+      if @backend
+        quit_request = send("quit", :header => header_for_close) do
+          yield if block_given?
+        end
+        sequential_request << quit_request
       end
-      sequential_request << quit_request
 
       if sync
         sequential_request.wait
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190511/6ec002eb/attachment-0001.html>


More information about the Groonga-commit mailing list
アーカイブの一覧に戻る