mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -419,8 +419,11 @@ luaS_clonestring(lua_State *L, TString *ts) {
|
||||
result = query_ptr(ts);
|
||||
if (result)
|
||||
return result;
|
||||
// ts is not in SSM, so recalc hash, and add it to SSM
|
||||
h = luaS_hash(str, l, 0);
|
||||
result = query_string(h, str, l);
|
||||
if (result)
|
||||
return result;
|
||||
// ts is not in SSM, so recalc hash, and add it to SSM
|
||||
return add_string(h, str, l);
|
||||
}
|
||||
|
||||
|
||||
@@ -885,7 +885,12 @@ int lhmac_sha1(lua_State *L);
|
||||
int
|
||||
luaopen_crypt(lua_State *L) {
|
||||
luaL_checkversion(L);
|
||||
static int init = 0;
|
||||
if (!init) {
|
||||
// Don't need call srandom more than once.
|
||||
init = 1 ;
|
||||
srandom(time(NULL));
|
||||
}
|
||||
luaL_Reg l[] = {
|
||||
{ "hashkey", lhashkey },
|
||||
{ "randomkey", lrandomkey },
|
||||
|
||||
@@ -469,7 +469,7 @@ lpack(lua_State *L) {
|
||||
size_t sz=0;
|
||||
const void * buffer = getbuffer(L, 1, &sz);
|
||||
// the worst-case space overhead of packing is 2 bytes per 2 KiB of input (256 words = 2KiB).
|
||||
size_t maxsz = (sz + 2047) / 2048 * 2 + sz;
|
||||
size_t maxsz = (sz + 2047) / 2048 * 2 + sz + 2;
|
||||
void * output = lua_touserdata(L, lua_upvalueindex(1));
|
||||
int bytes;
|
||||
int osz = lua_tointeger(L, lua_upvalueindex(2));
|
||||
|
||||
@@ -72,7 +72,8 @@ local function request(fd, method, host, url, recvheader, header, content)
|
||||
body = body .. padding
|
||||
end
|
||||
else
|
||||
body = nil
|
||||
-- no content-length, read all
|
||||
body = body .. socket.readall(fd)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ function sockethelper.readfunc(fd)
|
||||
end
|
||||
end
|
||||
|
||||
sockethelper.readall = socket.readall
|
||||
|
||||
function sockethelper.writefunc(fd)
|
||||
return function(content)
|
||||
local ok = writebytes(fd, content)
|
||||
|
||||
@@ -125,19 +125,6 @@ local function _compose_packet(self, req, size)
|
||||
return packet
|
||||
end
|
||||
|
||||
|
||||
local function _send_packet(self, req, size)
|
||||
local sock = self.sock
|
||||
|
||||
self.packet_no = self.packet_no + 1
|
||||
|
||||
|
||||
local packet = _set_byte3(size) .. strchar(self.packet_no) .. req
|
||||
|
||||
return socket.write(self.sock,packet)
|
||||
end
|
||||
|
||||
|
||||
local function _recv_packet(self,sock)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
local io = io
|
||||
local table = table
|
||||
local debug = debug
|
||||
|
||||
return function (skynet, export)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local skynet = require "skynet"
|
||||
local debugchannel = require "debugchannel"
|
||||
local socket = require "socket"
|
||||
local socketdriver = require "socketdriver"
|
||||
local injectrun = require "skynet.injectcode"
|
||||
local table = table
|
||||
local debug = debug
|
||||
@@ -56,7 +56,7 @@ local function gen_print(fd)
|
||||
tmp[i] = tostring(tmp[i])
|
||||
end
|
||||
table.insert(tmp, "\n")
|
||||
socket.write(fd, table.concat(tmp, "\t"))
|
||||
socketdriver.send(fd, table.concat(tmp, "\t"))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -140,10 +140,13 @@ end
|
||||
local function watch_proto(protoname, cond)
|
||||
local proto = assert(replace_upvalue(skynet.register_protocol, "proto"), "Can't find proto table")
|
||||
local p = proto[protoname]
|
||||
local dispatch = p.dispatch_origin or p.dispatch
|
||||
if p == nil or dispatch == nil then
|
||||
if p == nil then
|
||||
return "No " .. protoname
|
||||
end
|
||||
local dispatch = p.dispatch_origin or p.dispatch
|
||||
if dispatch == nil then
|
||||
return "No dispatch"
|
||||
end
|
||||
p.dispatch_origin = dispatch
|
||||
p.dispatch = function(...)
|
||||
if not cond or cond(...) then
|
||||
@@ -208,7 +211,7 @@ local function hook_dispatch(dispatcher, resp, fd, channel)
|
||||
local function debug_hook()
|
||||
while true do
|
||||
if newline then
|
||||
socket.write(fd, prompt)
|
||||
socketdriver.send(fd, prompt)
|
||||
newline = false
|
||||
end
|
||||
local cmd = channel:read()
|
||||
@@ -244,8 +247,10 @@ local function hook_dispatch(dispatcher, resp, fd, channel)
|
||||
func = replace_upvalue(dispatcher, HOOK_FUNC, hook)
|
||||
if func then
|
||||
local function idle()
|
||||
if raw_dispatcher then
|
||||
skynet.timeout(10,idle) -- idle every 0.1s
|
||||
end
|
||||
end
|
||||
skynet.timeout(0, idle)
|
||||
end
|
||||
return func
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
local si = require "snax.interface"
|
||||
local io = io
|
||||
|
||||
local hotfix = {}
|
||||
|
||||
local function envid(f)
|
||||
local i = 1
|
||||
|
||||
@@ -411,10 +411,10 @@ end
|
||||
|
||||
function channel:close()
|
||||
if not self.__closed then
|
||||
local thread = assert(self.__dispatch_thread)
|
||||
local thread = self.__dispatch_thread
|
||||
self.__closed = true
|
||||
close_channel_socket(self)
|
||||
if not self.__response and self.__dispatch_thread == thread then
|
||||
if not self.__response and self.__dispatch_thread == thread and thread then
|
||||
-- dispatch by order, send close signal to dispatch thread
|
||||
push_response(self, true, false) -- (true, false) is close signal
|
||||
end
|
||||
|
||||
@@ -346,7 +346,6 @@ dispatch_name_queue(struct harbor *h, struct keyvalue * node) {
|
||||
struct harbor_msg_queue * queue = node->queue;
|
||||
uint32_t handle = node->value;
|
||||
int harbor_id = handle >> HANDLE_REMOTE_SHIFT;
|
||||
assert(harbor_id != 0);
|
||||
struct skynet_context * context = h->ctx;
|
||||
struct slave *s = &h->s[harbor_id];
|
||||
int fd = s->fd;
|
||||
@@ -366,6 +365,16 @@ dispatch_name_queue(struct harbor *h, struct keyvalue * node) {
|
||||
push_queue_msg(s->queue, m);
|
||||
}
|
||||
}
|
||||
if (harbor_id == (h->slave >> HANDLE_REMOTE_SHIFT)) {
|
||||
// the harbor_id is local
|
||||
struct harbor_msg * m;
|
||||
while ((m = pop_queue(s->queue)) != NULL) {
|
||||
int type = m->header.destination >> HANDLE_REMOTE_SHIFT;
|
||||
skynet_send(context, m->header.source, handle , type | PTYPE_TAG_DONTCOPY, m->header.session, m->buffer, m->size);
|
||||
}
|
||||
release_queue(s->queue);
|
||||
s->queue = NULL;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user