mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add QUERY command to query local service address
This commit is contained in:
@@ -158,6 +158,10 @@ function skynet.self()
|
||||
return self_handle
|
||||
end
|
||||
|
||||
function skynet.localname(name)
|
||||
return string_to_handle(c.command("QUERY", name))
|
||||
end
|
||||
|
||||
function skynet.launch(...)
|
||||
local addr = c.command("LAUNCH", table.concat({...}," "))
|
||||
if addr then
|
||||
|
||||
@@ -14,6 +14,7 @@ local READTHREAD= {} -- fd:thread
|
||||
local CLOSED = {} -- fd:true
|
||||
|
||||
local selfaddr = skynet.self()
|
||||
local sockets = assert(skynet.localname ".socket")
|
||||
|
||||
local function response(session)
|
||||
skynet.redirect(selfaddr , 0, "response", session, "")
|
||||
@@ -94,7 +95,7 @@ local socket = {}
|
||||
|
||||
function socket.open(addr, port)
|
||||
local cmd = "open" .. " " .. (port and (addr..":"..port) or addr)
|
||||
local r = skynet.call(".socket", "text", cmd)
|
||||
local r = skynet.call(sockets, "text", cmd)
|
||||
if r == "" then
|
||||
return nil, cmd .. " failed"
|
||||
end
|
||||
@@ -105,7 +106,7 @@ function socket.open(addr, port)
|
||||
end
|
||||
|
||||
function socket.stdin()
|
||||
local r = skynet.call(".socket", "text", "bind 1")
|
||||
local r = skynet.call(sockets, "text", "bind 1")
|
||||
if r == "" then
|
||||
error("stdin bind failed")
|
||||
end
|
||||
@@ -117,7 +118,7 @@ end
|
||||
|
||||
function socket.close(fd)
|
||||
socket.lock(fd)
|
||||
skynet.call(".socket", "text", "close", fd)
|
||||
skynet.call(sockets, "text", "close", fd)
|
||||
READBUF[fd] = nil
|
||||
READLOCK[fd] = nil
|
||||
CLOSED[fd] = nil
|
||||
@@ -221,7 +222,7 @@ function socket.write(fd, msg, sz)
|
||||
if CLOSED[fd] or not READBUF[fd] then
|
||||
return
|
||||
end
|
||||
skynet.send(".socket", "client", fd, msg, sz)
|
||||
skynet.send(sockets, "client", fd, msg, sz)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
@@ -384,6 +384,15 @@ skynet_command(struct skynet_context * context, const char * cmd , const char *
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(cmd,"QUERY") == 0) {
|
||||
if (param[0] == '.') {
|
||||
uint32_t handle = skynet_handle_findname(param+1);
|
||||
sprintf(context->result, ":%x", handle);
|
||||
return context->result;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strcmp(cmd,"NAME") == 0) {
|
||||
int size = strlen(param);
|
||||
char name[size+1];
|
||||
|
||||
Reference in New Issue
Block a user