]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
vici: Handle closed sockets in the Ruby gem
authorEvan Broder <evan@stripe.com>
Sat, 22 Aug 2015 23:20:40 +0000 (19:20 -0400)
committerTobias Brunner <tobias@strongswan.org>
Mon, 24 Aug 2015 09:24:05 +0000 (11:24 +0200)
From recvfrom(2) (which UDPSocket#recv backs into):

  The return value will be 0 when the peer has performed an orderly
  shutdown.

(i.e. it will return an empty string)

Previously in this scenario, Vici::Transport#recv_all would spin
forever trying to pull more data off the socket. I'm not entirely
clear what happened that caused strongSwan to shutdown the socket, but
it probably should not cause vici Ruby apps to spin.

Closes strongswan/strongswan#13.

src/libcharon/plugins/vici/ruby/lib/vici.rb

index f87e46e692e6ec5eb1c74a86f280888203c4c410..f8169add0706e06beefae20d6d6256e388747e39 100644 (file)
@@ -247,7 +247,11 @@ module Vici
     def recv_all(len)
       encoding = ""
       while encoding.length < len do
-        encoding << @socket.recv(len - encoding.length)
+        data = @socket.recv(len - encoding.length)
+        if data.empty?
+          raise TransportError, "connection closed"
+        end
+        encoding << data
       end
       encoding
     end