From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladislav Shpilevoy Subject: [PATCH 8/8] netbox: implement perform_request via async version Date: Mon, 16 Apr 2018 21:39:18 +0300 Message-Id: <8562701387bad232860bbb98371f5be067754c97.1523903144.git.v.shpilevoy@tarantool.org> In-Reply-To: References: In-Reply-To: References: To: tarantool-patches@freelists.org Cc: vdavydov.dev@gmail.com List-ID: When async netbox was introduced, it is not needed to hold a special sync implementation - it can be just async call + waiting for a response. Closes #3107 --- src/box/lua/net_box.lua | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua index a2b7b39d2..6b33f70c7 100644 --- a/src/box/lua/net_box.lua +++ b/src/box/lua/net_box.lua @@ -437,24 +437,16 @@ local function create_transport(host, port, user, password, callback, -- -- Send a request and wait for response. + -- @retval nil, error Error occured. + -- @retval not nil Response object. -- local function perform_request(timeout, buffer, method, ...) local request, err = perform_async_request(buffer, method, ...) if not request then - return last_errno or E_NO_CONNECTION, last_error + return nil, err end - request.client = fiber_self() - local id = request.id - local deadline = fiber_clock() + (timeout or TIMEOUT_INFINITY) - repeat - local timeout = max(0, deadline - fiber_clock()) - if not state_cond:wait(timeout) then - requests[id] = nil - return E_TIMEOUT, 'Timeout exceeded' - end - until requests[id] == nil -- i.e. completed (beware spurious wakeups) - return request.errno, request.response + return request:wait_result(timeout) end local function dispatch_response_iproto(hdr, body_rpos, body_end) @@ -988,9 +980,9 @@ function remote_methods:_request(method, opts, ...) transport.wait_state('active', timeout) timeout = deadline and max(0, deadline - fiber_clock()) end - local err, res = transport.perform_request(timeout, buffer, method, ...) + local res, err = transport.perform_request(timeout, buffer, method, ...) if err then - box.error({code = err, reason = res}) + box.error.raise(err) end -- Try to wait until a schema is reloaded if needed. -- Regardless of reloading result, the main response is @@ -1182,13 +1174,13 @@ function console_methods:eval(line, timeout) end if self.protocol == 'Binary' then local loader = 'return require("console").eval(...)' - err, res = pr(timeout, nil, 'eval', loader, {line}) + res, err = pr(timeout, nil, 'eval', loader, {line}) else assert(self.protocol == 'Lua console') - err, res = pr(timeout, nil, 'inject', line..'$EOF$\n') + res, err = pr(timeout, nil, 'inject', line..'$EOF$\n') end if err then - box.error({code = err, reason = res}) + box.error.raise(err) end return res[1] or res end -- 2.15.1 (Apple Git-101)