[tarantool-patches] [PATCH 1/3] netbox: allow to create a netbox connection from existing socket
v.shpilevoy at tarantool.org
v.shpilevoy at tarantool.org
Fri Mar 23 13:01:45 MSK 2018
I have found, that SIGPIPE appears only under a debugger (lldb or gdb), but it does not mean, that it's ok to crash during debugging. I leave the try-to-read-before-write fix, but I made it slightly more simple. Instead of storing read symbols in a buffer I just mark them as unread in ibuf. The patch is below and on the branch.
diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua
index 02e7f1066..633144c7f 100644
--- a/src/box/lua/console.lua
+++ b/src/box/lua/console.lua
@@ -94,20 +94,19 @@ local text_connection_mt = {
-- @retval nil Error.
--
write = function(self, text)
- -- It is the hack to protect from SIGPIPE on send in
+ -- It is the hack to protect from SIGPIPE, which is
+ -- not ignored under debugger (gdb, lldb) on send in
-- a socket, that is actually closed. If a socket is
-- readable and read() returns nothing then the socket
-- is closed, and writing into it will raise SIGPIPE.
if self._socket:readable(0) then
- local rc = self._socket:recv(1)
+ local rc = self._socket:read({chunk = 1})
if not rc or rc == '' then
return nil
else
- -- But if it was literally readable, the
- -- single read byte can not be put back, and
- -- must be stored somewhere, until console
- -- do read().
- self.buffer = self.buffer..rc
+ assert(#rc == 1)
+ -- Make the char be unread.
+ self._socket.rbuf.wpos = self._socket.rbuf.wpos - 1
end
end
return self._socket:send(text)
@@ -120,8 +119,6 @@ local text_connection_mt = {
read = function(self)
local ret = self._socket:read(YAML_TERM)
if ret and ret ~= '' then
- ret = (self.buffer or '')..ret
- self.buffer = nil
return ret
end
end,
@@ -168,7 +165,6 @@ local function wrap_text_socket(connection, url)
state = 'active',
host = url.host or 'localhost',
port = url.service,
- buffer = nil,
}, text_connection_mt)
if not conn:write('require("console").delimiter("$EOF$")\n') or
not conn:read() then
More information about the Tarantool-patches
mailing list