X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=libs%2Fnixio%2Flua%2Fnixio%2Futil.lua;h=409004882dc86e69d87ce539188cb1065ad0d615;hb=7b5cdb36b5c8d4e412eeda80f8a04a2208a329bf;hp=2c9fc93a3eef98bff3c44acdbe7f4a25a47b8f07;hpb=a2b916ab736802050b19562b7c163e3f3bb1566f;p=project%2Fluci.git diff --git a/libs/nixio/lua/nixio/util.lua b/libs/nixio/lua/nixio/util.lua index 2c9fc93a3..409004882 100644 --- a/libs/nixio/lua/nixio/util.lua +++ b/libs/nixio/lua/nixio/util.lua @@ -14,7 +14,8 @@ $Id$ local table = require "table" local nixio = require "nixio" -local getmetatable, assert, pairs = getmetatable, assert, pairs +local getmetatable, assert, pairs, type = getmetatable, assert, pairs, type +local tostring = tostring module "nixio.util" @@ -23,11 +24,15 @@ local ZIOBLKSIZE = 65536 local socket = nixio.meta_socket local tls_socket = nixio.meta_tls_socket local file = nixio.meta_file - -function consume(iter) - local tbl = {} - for obj in iter do - tbl[#tbl+1] = obj +local uname = nixio.uname() +local ZBUG = uname.sysname == "Linux" and uname.release:sub(1, 3) == "2.4" + +function consume(iter, append) + local tbl = append or {} + if iter then + for obj in iter do + tbl[#tbl+1] = obj + end end return tbl end @@ -75,6 +80,7 @@ end meta.recvall = meta.readall function meta.writeall(self, data) + data = tostring(data) local sent, code, msg = self:write(data) if not sent then @@ -106,7 +112,7 @@ function meta.linesource(self, limit) if flush then line = buffer:sub(bpos + 1) - buffer = "" + buffer = type(flush) == "string" and flush or "" bpos = 0 return line end @@ -189,8 +195,11 @@ end function meta.copyz(self, fd, size) local sent, lsent, code, msg = 0 - if self:is_file() then - if nixio.sendfile and fd:is_socket() and self:stat("type") == "reg" then + local splicable + + if not ZBUG and self:is_file() then + local ftype = self:stat("type") + if nixio.sendfile and fd:is_socket() and ftype == "reg" then repeat lsent, code, msg = nixio.sendfile(fd, self, size or ZIOBLKSIZE) if lsent then @@ -202,7 +211,27 @@ function meta.copyz(self, fd, size) code ~= nixio.const.ENOSYS and code ~= nixio.const.EINVAL) then return lsent and sent, code, msg, sent end - end + elseif nixio.splice and not fd:is_tls_socket() and ftype == "fifo" then + splicable = true + end + end + + if nixio.splice and fd:is_file() and not splicable then + splicable = not self:is_tls_socket() and fd:stat("type") == "fifo" + end + + if splicable then + repeat + lsent, code, msg = nixio.splice(self, fd, size or ZIOBLKSIZE) + if lsent then + sent = sent + lsent + size = size and (size - lsent) + end + until (not lsent or lsent == 0 or (size and size == 0)) + if lsent or (not lsent and sent == 0 and + code ~= nixio.const.ENOSYS and code ~= nixio.const.EINVAL) then + return lsent and sent, code, msg, sent + end end return self:copy(fd, size) @@ -212,8 +241,26 @@ function tls_socket.close(self) return self.socket:close() end +function tls_socket.getsockname(self) + return self.socket:getsockname() +end + +function tls_socket.getpeername(self) + return self.socket:getpeername() +end + +function tls_socket.getsockopt(self, ...) + return self.socket:getsockopt(...) +end +tls_socket.getopt = tls_socket.getsockopt + +function tls_socket.setsockopt(self, ...) + return self.socket:setsockopt(...) +end +tls_socket.setopt = tls_socket.setsockopt + for k, v in pairs(meta) do file[k] = v socket[k] = v tls_socket[k] = v -end \ No newline at end of file +end