summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-11 07:51:53 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-11 07:51:53 +0000
commit0a954e9117168f0221b7cfd833b1e2ea6243ba16 (patch)
treec4fca19ab1a781f28f36c12c02c018fece547b3f
parentff955766d496954140ed9c72ac0be898cbb913da (diff)
* ext/socket/lib/socket.rb (Socket.unix_server_socket): call the block
if given. remove the socket file when the block exits. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/socket/lib/socket.rb11
-rw-r--r--test/socket/test_unix.rb11
3 files changed, 26 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 24ddce1a89..4af8b7d3a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Feb 11 16:50:59 2009 Tanaka Akira <akr@fsij.org>
+
+ * 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@fsij.org>
* ext/socket/ancdata.c (ancillary_s_ip_pktinfo): make 3rd argument
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index 0981b12edc..1099b7fd2f 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -607,7 +607,16 @@ class Socket
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_.
diff --git a/test/socket/test_unix.rb b/test/socket/test_unix.rb
index d3b17450f1..2b1f4deb33 100644
--- a/test/socket/test_unix.rb
+++ b/test/socket/test_unix.rb
@@ -296,6 +296,17 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
}
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|