Skip to content
Snippets Groups Projects
Commit 67c06fd4 authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

bsdsocket: always assume the socket is ready

parent 18462a6b
No related branches found
No related tags found
No related merge requests found
...@@ -561,15 +561,9 @@ local function readchunk(self, limit, timeout) ...@@ -561,15 +561,9 @@ local function readchunk(self, limit, timeout)
return data return data
end end
while timeout > 0 do while true do
local started = fiber.time() local started = fiber.time()
if not self:readable(timeout) then
return nil
end
timeout = timeout - ( fiber.time() - started )
local to_read local to_read
if limit ~= LIMIT_INFINITY and limit > READAHEAD then if limit ~= LIMIT_INFINITY and limit > READAHEAD then
to_read = limit - self.rlen to_read = limit - self.rlen
...@@ -588,11 +582,18 @@ local function readchunk(self, limit, timeout) ...@@ -588,11 +582,18 @@ local function readchunk(self, limit, timeout)
self.rpos = self.rpos + limit self.rpos = self.rpos + limit
return data return data
end end
elseif not errno_is_transient[self:errno()] then elseif not errno_is_transient[self:errno()] then
self._errno = boxerrno() self._errno = boxerrno()
return nil return nil
end end
if not self:readable(timeout) then
return nil
end
if timeout <= 0 then
break
end
timeout = timeout - ( fiber.time() - started )
end end
self._errno = boxerrno.ETIMEDOUT self._errno = boxerrno.ETIMEDOUT
return nil return nil
...@@ -680,7 +681,7 @@ end ...@@ -680,7 +681,7 @@ end
socket_methods.read = function(self, opts, timeout) socket_methods.read = function(self, opts, timeout)
check_socket(self) check_socket(self)
timeout = timeout and tonumber(timeout) or TIMEOUT_INFINITY timeout = timeout or TIMEOUT_INFINITY
if type(opts) == 'number' then if type(opts) == 'number' then
return readchunk(self, opts, timeout) return readchunk(self, opts, timeout)
elseif type(opts) == 'string' then elseif type(opts) == 'string' then
...@@ -706,9 +707,7 @@ socket_methods.write = function(self, octets, timeout) ...@@ -706,9 +707,7 @@ socket_methods.write = function(self, octets, timeout)
end end
local started = fiber.time() local started = fiber.time()
while timeout > 0 and self:writable(timeout) do while true do
timeout = timeout - ( fiber.time() - started )
local written = self:syswrite(octets) local written = self:syswrite(octets)
if written == nil then if written == nil then
if not errno_is_transient[self:errno()] then if not errno_is_transient[self:errno()] then
...@@ -722,6 +721,10 @@ socket_methods.write = function(self, octets, timeout) ...@@ -722,6 +721,10 @@ socket_methods.write = function(self, octets, timeout)
if written > 0 then if written > 0 then
octets = string.sub(octets, written + 1) octets = string.sub(octets, written + 1)
end end
timeout = timeout - (fiber.time() - started)
if timeout <= 0 or self:writable(timeout) then
break
end
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment