mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/ruby/test_io.rb (TestIO#test_fcntl_lock): small clean up.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b110abbecb
commit
a474b0e3f7
2 changed files with 31 additions and 28 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Sat Mar 5 19:44:03 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
|
* test/ruby/test_io.rb (TestIO#test_fcntl_lock): small clean up.
|
||||||
|
|
||||||
Sat Mar 5 01:33:46 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
Sat Mar 5 01:33:46 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
* io.c (io_cntl, nogvl_io_cntl): IO.fcntl() and IO.ioctl()
|
* io.c (io_cntl, nogvl_io_cntl): IO.fcntl() and IO.ioctl()
|
||||||
|
|
|
@ -1777,21 +1777,15 @@ End
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if /x86_64-linux/ =~ RUBY_PLATFORM # A binary form of struct flock depend on platform
|
|
||||||
F_WRLCK = 1
|
|
||||||
F_UNLCK = 2
|
|
||||||
SEEK_SET = 0
|
|
||||||
|
|
||||||
def test_fcntl_lock
|
def test_fcntl_lock
|
||||||
pad = 0
|
return if /x86_64-linux/ !~ RUBY_PLATFORM # A binary form of struct flock depend on platform
|
||||||
flocktype = "s!s!s!s!L!L!i!"
|
|
||||||
|
|
||||||
|
pad=0
|
||||||
Tempfile.open(self.class.name) do |f|
|
Tempfile.open(self.class.name) do |f|
|
||||||
r, w = IO.pipe
|
r, w = IO.pipe
|
||||||
pid = fork do
|
pid = fork do
|
||||||
r.close
|
r.close
|
||||||
lock = [F_WRLCK, SEEK_SET, pad, pad, 0, 0, 0].pack(flocktype)
|
lock = [Fcntl::F_WRLCK, IO::SEEK_SET, pad, 12, 34, 0].pack("s!s!i!L!L!i!")
|
||||||
f.fcntl Fcntl::F_SETLKW, lock
|
f.fcntl Fcntl::F_SETLKW, lock
|
||||||
w.syswrite "."
|
w.syswrite "."
|
||||||
sleep
|
sleep
|
||||||
|
@ -1800,14 +1794,19 @@ End
|
||||||
assert_equal ".", r.read(1)
|
assert_equal ".", r.read(1)
|
||||||
r.close
|
r.close
|
||||||
pad = 0
|
pad = 0
|
||||||
getlock = [F_WRLCK, 0, pad, pad, 0, 0, 0].pack(flocktype)
|
getlock = [Fcntl::F_WRLCK, 0, pad, 0, 0, 0].pack("s!s!i!L!L!i!")
|
||||||
f.fcntl Fcntl::F_GETLK, getlock
|
f.fcntl Fcntl::F_GETLK, getlock
|
||||||
|
|
||||||
ptype, whence, pad, pad, start, len, lockpid = getlock.unpack(flocktype)
|
ptype, whence, pad, start, len, lockpid = getlock.unpack("s!s!i!L!L!i!")
|
||||||
|
|
||||||
|
assert_equal(ptype, Fcntl::F_WRLCK)
|
||||||
|
assert_equal(whence, IO::SEEK_SET)
|
||||||
|
assert_equal(start, 12)
|
||||||
|
assert_equal(len, 34)
|
||||||
assert_equal(pid, lockpid)
|
assert_equal(pid, lockpid)
|
||||||
|
|
||||||
Process.kill :TERM, pid
|
Process.kill :TERM, pid
|
||||||
Process.waitpid2(pid)
|
Process.waitpid2(pid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue