diff --git a/src/lua/fio.lua b/src/lua/fio.lua index d48c709b158ee9c5a3076986afb9f259db5a3c03..73719df90e00bc6d2f403787e3f7bbb1dca10512 100644 --- a/src/lua/fio.lua +++ b/src/lua/fio.lua @@ -40,8 +40,7 @@ fio_methods.read = function(self, buf, size) end if not ffi.istype(const_char_ptr_t, buf) then size = buf or size - tmpbuf = buffer.IBUF_SHARED - tmpbuf:reset() + tmpbuf = buffer.ibuf() buf = tmpbuf:reserve(size) end local res, err = internal.read(self.fh, buf, size) diff --git a/test/app/fio.result b/test/app/fio.result index 0fc858253074306e3b106c2004363487745102fe..6c4609855f0dc2350a1d8ecdb7e6fb22b401c464 100644 --- a/test/app/fio.result +++ b/test/app/fio.result @@ -1067,6 +1067,76 @@ fio.unlink(tmpfile) --- - true ... +tmp1 = fio.pathjoin(tmpdir, "tmp1") +--- +... +tmp2= fio.pathjoin(tmpdir, "tmp2") +--- +... +test_run:cmd("setopt delimiter ';'") +--- +- true +... +function write_file(name, odd) + local fh = fio.open(name, { 'O_RDWR', 'O_TRUNC', 'O_CREAT' }, 0777) + if odd then + fh:write(string.rep('1', 100)) + else + fh:write(string.rep('2', 100)) + end + fh:write(name) + fh:seek(0) + return fh +end; +--- +... +test_run:cmd("setopt delimiter ''"); +--- +- true +... +fh1 = write_file(tmp1) +--- +... +fh2 = write_file(tmp2) +--- +... +fiber = require('fiber') +--- +... +digest = require('digest') +--- +... +str = fh1:read() +--- +... +fh1:seek(0) +--- +- 0 +... +hash = digest.crc32(str) +--- +... +ch = fiber.channel(1) +--- +... +f1 = fiber.create(function() str = fh1:read() ch:put(digest.crc32(str)) end) +--- +... +f2 = fiber.create(function() str = fh2:read() end) +--- +... +ch:get() == hash +--- +- true +... +fio.unlink(tmp1) +--- +- true +... +fio.unlink(tmp2) +--- +- true +... fio.rmdir(tmpdir) --- - true diff --git a/test/app/fio.test.lua b/test/app/fio.test.lua index cd0bc16c650f1e8894c862d4c83a2c5dd27d43e0..0850413d9b96cccf05d7d73e743ef9e1e836658a 100644 --- a/test/app/fio.test.lua +++ b/test/app/fio.test.lua @@ -342,4 +342,33 @@ fio.path.lexists(link) fio.unlink(link) fio.unlink(tmpfile) +tmp1 = fio.pathjoin(tmpdir, "tmp1") +tmp2= fio.pathjoin(tmpdir, "tmp2") +test_run:cmd("setopt delimiter ';'") +function write_file(name, odd) + local fh = fio.open(name, { 'O_RDWR', 'O_TRUNC', 'O_CREAT' }, 0777) + if odd then + fh:write(string.rep('1', 100)) + else + fh:write(string.rep('2', 100)) + end + fh:write(name) + fh:seek(0) + return fh +end; +test_run:cmd("setopt delimiter ''"); +fh1 = write_file(tmp1) +fh2 = write_file(tmp2) +fiber = require('fiber') +digest = require('digest') +str = fh1:read() +fh1:seek(0) +hash = digest.crc32(str) +ch = fiber.channel(1) +f1 = fiber.create(function() str = fh1:read() ch:put(digest.crc32(str)) end) +f2 = fiber.create(function() str = fh2:read() end) +ch:get() == hash + +fio.unlink(tmp1) +fio.unlink(tmp2) fio.rmdir(tmpdir)