[前][次][番号順一覧][スレッド一覧]

ruby-changes:10670

From: akr <ko1@a...>
Date: Wed, 11 Feb 2009 16:52:05 +0900 (JST)
Subject: [ruby-changes:10670] Ruby:r22233 (trunk): * ext/socket/lib/socket.rb (Socket.unix_server_socket): call the block

akr	2009-02-11 16:51:53 +0900 (Wed, 11 Feb 2009)

  New Revision: 22233

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22233

  Log:
    * ext/socket/lib/socket.rb (Socket.unix_server_socket): call the block
      if given.  remove the socket file when the block exits.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/lib/socket.rb
    trunk/test/socket/test_unix.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 22232)
+++ ChangeLog	(revision 22233)
@@ -1,3 +1,8 @@
+Wed Feb 11 16:50:59 2009  Tanaka Akira  <akr@f...>
+
+	* ext/socket/lib/socket.rb (Socket.unix_server_socket): call the block
+	  if given.  remove the socket file when the block exits.
+
 Wed Feb 11 16:44:20 2009  Tanaka Akira  <akr@f...>
 
 	* ext/socket/ancdata.c (ancillary_s_ip_pktinfo): make 3rd argument
Index: ext/socket/lib/socket.rb
===================================================================
--- ext/socket/lib/socket.rb	(revision 22232)
+++ ext/socket/lib/socket.rb	(revision 22233)
@@ -607,7 +607,16 @@
     if st && st.socket? && st.owned?
       File.unlink path
     end
-    Addrinfo.unix(path).listen
+    s = Addrinfo.unix(path).listen
+    if block_given?
+      begin
+        yield s
+      ensure
+        File.unlink path
+      end
+    else
+      s
+    end
   end
 
   # creates a UNIX socket server on _path_.
Index: test/socket/test_unix.rb
===================================================================
--- test/socket/test_unix.rb	(revision 22232)
+++ test/socket/test_unix.rb	(revision 22233)
@@ -296,6 +296,17 @@
     }
   end
 
+  def test_unix_server_socket
+    Dir.mktmpdir {|d|
+      path = "#{d}/sock"
+      Socket.unix_server_socket(path) {|s|
+        assert_equal(path, s.local_address.unix_path)
+        assert(File.socket?(path))
+      }
+      assert_raise(Errno::ENOENT) { File.stat path }
+    }
+  end
+
   def test_getcred_ucred
     return if /linux/ !~ RUBY_PLATFORM
     Dir.mktmpdir {|d|

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]