mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
error on call an invalid address
This commit is contained in:
@@ -309,7 +309,7 @@ _send(lua_State *L) {
|
|||||||
if (session < 0) {
|
if (session < 0) {
|
||||||
// send to invalid address
|
// send to invalid address
|
||||||
// todo: maybe throw error is better
|
// todo: maybe throw error is better
|
||||||
session = 0;
|
return 0;
|
||||||
}
|
}
|
||||||
lua_pushinteger(L,session);
|
lua_pushinteger(L,session);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -233,20 +233,24 @@ skynet.tostring = assert(c.tostring)
|
|||||||
function skynet.call(addr, typename, ...)
|
function skynet.call(addr, typename, ...)
|
||||||
local p = proto[typename]
|
local p = proto[typename]
|
||||||
local session = c.send(addr, p.id , nil , p.pack(...))
|
local session = c.send(addr, p.id , nil , p.pack(...))
|
||||||
return p.unpack(coroutine_yield("CALL", session))
|
return p.unpack(coroutine_yield("CALL", assert(session, "call to invalid address")))
|
||||||
end
|
end
|
||||||
|
|
||||||
function skynet.blockcall(addr, typename , ...)
|
function skynet.blockcall(addr, typename , ...)
|
||||||
local p = proto[typename]
|
local p = proto[typename]
|
||||||
c.command("LOCK")
|
c.command("LOCK")
|
||||||
local session = c.send(addr, p.id , nil , p.pack(...))
|
local session = c.send(addr, p.id , nil , p.pack(...))
|
||||||
|
if session == nil then
|
||||||
|
c.command("UNLOCK")
|
||||||
|
error("call to invalid address")
|
||||||
|
end
|
||||||
return p.unpack(coroutine_yield("CALL", session))
|
return p.unpack(coroutine_yield("CALL", session))
|
||||||
end
|
end
|
||||||
|
|
||||||
function skynet.rawcall(addr, typename, msg, sz)
|
function skynet.rawcall(addr, typename, msg, sz)
|
||||||
local p = proto[typename]
|
local p = proto[typename]
|
||||||
local session = c.send(addr, p.id , nil , msg, sz)
|
local session = c.send(addr, p.id , nil , msg, sz)
|
||||||
return coroutine_yield("CALL", session)
|
return coroutine_yield("CALL", assert(session, "call to invalid address"))
|
||||||
end
|
end
|
||||||
|
|
||||||
function skynet.ret(msg, sz)
|
function skynet.ret(msg, sz)
|
||||||
@@ -405,7 +409,7 @@ do
|
|||||||
f = function(...)
|
f = function(...)
|
||||||
local addr = remote_query(t.__remote)
|
local addr = remote_query(t.__remote)
|
||||||
-- the proto is 11 (lua is 10)
|
-- the proto is 11 (lua is 10)
|
||||||
local session = _send(addr, 11 , nil, _pack(t,method,...))
|
local session = assert(_send(addr, 11 , nil, _pack(t,method,...)), "call to invalid address")
|
||||||
local msg, sz = _yield("CALL", session)
|
local msg, sz = _yield("CALL", session)
|
||||||
return select(2,assert(_unpack(msg,sz)))
|
return select(2,assert(_unpack(msg,sz)))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -147,6 +147,19 @@ expand_queue(struct message_queue *q) {
|
|||||||
q->queue = new_queue;
|
q->queue = new_queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_unlock(struct message_queue *q) {
|
||||||
|
// this api use in push a unlock message, so the in_global flags must not be 0 ,
|
||||||
|
// but the q is not exist in global queue.
|
||||||
|
if (q->in_global == MQ_LOCKED) {
|
||||||
|
skynet_globalmq_push(q);
|
||||||
|
q->in_global = MQ_IN_GLOBAL;
|
||||||
|
} else {
|
||||||
|
assert(q->in_global == MQ_DISPATCHING);
|
||||||
|
}
|
||||||
|
q->lock_session = 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_pushhead(struct message_queue *q, struct skynet_message *message) {
|
_pushhead(struct message_queue *q, struct skynet_message *message) {
|
||||||
int head = q->head - 1;
|
int head = q->head - 1;
|
||||||
@@ -162,15 +175,7 @@ _pushhead(struct message_queue *q, struct skynet_message *message) {
|
|||||||
q->queue[head] = *message;
|
q->queue[head] = *message;
|
||||||
q->head = head;
|
q->head = head;
|
||||||
|
|
||||||
// this api use in push a unlock message, so the in_global flags must not be 0 ,
|
_unlock(q);
|
||||||
// but the q is not exist in global queue.
|
|
||||||
if (q->in_global == MQ_LOCKED) {
|
|
||||||
skynet_globalmq_push(q);
|
|
||||||
q->in_global = MQ_IN_GLOBAL;
|
|
||||||
} else {
|
|
||||||
assert(q->in_global == MQ_DISPATCHING);
|
|
||||||
}
|
|
||||||
q->lock_session = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -211,6 +216,13 @@ skynet_mq_lock(struct message_queue *q, int session) {
|
|||||||
UNLOCK(q)
|
UNLOCK(q)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
skynet_mq_unlock(struct message_queue *q) {
|
||||||
|
LOCK(q)
|
||||||
|
_unlock(q);
|
||||||
|
UNLOCK(q)
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
skynet_mq_init() {
|
skynet_mq_init() {
|
||||||
struct global_queue *q = malloc(sizeof(*q));
|
struct global_queue *q = malloc(sizeof(*q));
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ uint32_t skynet_mq_handle(struct message_queue *);
|
|||||||
int skynet_mq_pop(struct message_queue *q, struct skynet_message *message);
|
int skynet_mq_pop(struct message_queue *q, struct skynet_message *message);
|
||||||
void skynet_mq_push(struct message_queue *q, struct skynet_message *message);
|
void skynet_mq_push(struct message_queue *q, struct skynet_message *message);
|
||||||
void skynet_mq_lock(struct message_queue *q, int session);
|
void skynet_mq_lock(struct message_queue *q, int session);
|
||||||
|
void skynet_mq_unlock(struct message_queue *q);
|
||||||
|
|
||||||
void skynet_mq_force_push(struct message_queue *q);
|
void skynet_mq_force_push(struct message_queue *q);
|
||||||
void skynet_mq_pushglobal(struct message_queue *q);
|
void skynet_mq_pushglobal(struct message_queue *q);
|
||||||
|
|||||||
@@ -384,6 +384,14 @@ skynet_command(struct skynet_context * context, const char * cmd , const char *
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp(cmd,"UNLOCK") == 0) {
|
||||||
|
if (context->init == false) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
skynet_mq_unlock(context->queue);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp(cmd,"REG") == 0) {
|
if (strcmp(cmd,"REG") == 0) {
|
||||||
if (param == NULL || param[0] == '\0') {
|
if (param == NULL || param[0] == '\0') {
|
||||||
sprintf(context->result, ":%x", context->handle);
|
sprintf(context->result, ":%x", context->handle);
|
||||||
|
|||||||
Reference in New Issue
Block a user