mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
skynet.redirect support string address
This commit is contained in:
@@ -30,7 +30,7 @@ void skynet_error(struct skynet_context * context, const char *msg, ...);
|
||||
const char * skynet_command(struct skynet_context * context, const char * cmd , const char * parm);
|
||||
uint32_t skynet_queryname(struct skynet_context * context, const char * name);
|
||||
int skynet_send(struct skynet_context * context, uint32_t source, uint32_t destination , int type, int session, void * msg, size_t sz);
|
||||
int skynet_sendname(struct skynet_context * context, const char * destination , int type, int session, void * msg, size_t sz);
|
||||
int skynet_sendname(struct skynet_context * context, uint32_t source, const char * destination , int type, int session, void * msg, size_t sz);
|
||||
|
||||
int skynet_isremote(struct skynet_context *, uint32_t handle, int * harbor);
|
||||
|
||||
|
||||
@@ -89,7 +89,6 @@ static const char * load_config = "\
|
||||
local code = assert(f:read \'*a\')\
|
||||
local function getenv(name) return assert(os.getenv(name), name) end\
|
||||
code = string.gsub(code, \'%$([%w_%d]+)\', getenv)\
|
||||
print(code)\
|
||||
f:close()\
|
||||
local result = {}\
|
||||
assert(load(code,\'=(load)\',\'t\',result))()\
|
||||
|
||||
@@ -614,8 +614,10 @@ skynet_send(struct skynet_context * context, uint32_t source, uint32_t destinati
|
||||
}
|
||||
|
||||
int
|
||||
skynet_sendname(struct skynet_context * context, const char * addr , int type, int session, void * data, size_t sz) {
|
||||
uint32_t source = context->handle;
|
||||
skynet_sendname(struct skynet_context * context, uint32_t source, const char * addr , int type, int session, void * data, size_t sz) {
|
||||
if (source == 0) {
|
||||
source = context->handle;
|
||||
}
|
||||
uint32_t des = 0;
|
||||
if (addr[0] == ':') {
|
||||
des = strtoul(addr+1, NULL, 16);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <sys/time.h>
|
||||
@@ -33,7 +34,7 @@ struct timer_event {
|
||||
|
||||
struct timer_node {
|
||||
struct timer_node *next;
|
||||
int expire;
|
||||
uint32_t expire;
|
||||
};
|
||||
|
||||
struct link_list {
|
||||
@@ -43,9 +44,9 @@ struct link_list {
|
||||
|
||||
struct timer {
|
||||
struct link_list near[TIME_NEAR];
|
||||
struct link_list t[4][TIME_LEVEL-1];
|
||||
struct link_list t[4][TIME_LEVEL];
|
||||
int lock;
|
||||
int time;
|
||||
uint32_t time;
|
||||
uint32_t current;
|
||||
uint32_t starttime;
|
||||
uint64_t current_point;
|
||||
@@ -72,21 +73,22 @@ link(struct link_list *list,struct timer_node *node) {
|
||||
|
||||
static void
|
||||
add_node(struct timer *T,struct timer_node *node) {
|
||||
int time=node->expire;
|
||||
int current_time=T->time;
|
||||
uint32_t time=node->expire;
|
||||
uint32_t current_time=T->time;
|
||||
|
||||
if ((time|TIME_NEAR_MASK)==(current_time|TIME_NEAR_MASK)) {
|
||||
link(&T->near[time&TIME_NEAR_MASK],node);
|
||||
} else {
|
||||
int i;
|
||||
int mask=TIME_NEAR << TIME_LEVEL_SHIFT;
|
||||
uint32_t mask=TIME_NEAR << TIME_LEVEL_SHIFT;
|
||||
for (i=0;i<3;i++) {
|
||||
if ((time|(mask-1))==(current_time|(mask-1))) {
|
||||
break;
|
||||
}
|
||||
mask <<= TIME_LEVEL_SHIFT;
|
||||
}
|
||||
link(&T->t[i][((time>>(TIME_NEAR_SHIFT + i*TIME_LEVEL_SHIFT)) & TIME_LEVEL_MASK)-1],node);
|
||||
|
||||
link(&T->t[i][((time>>(TIME_NEAR_SHIFT + i*TIME_LEVEL_SHIFT)) & TIME_LEVEL_MASK)],node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,29 +105,38 @@ timer_add(struct timer *T,void *arg,size_t sz,int time) {
|
||||
UNLOCK(T);
|
||||
}
|
||||
|
||||
static void
|
||||
move_list(struct timer *T, int level, int idx) {
|
||||
struct timer_node *current = link_clear(&T->t[level][idx]);
|
||||
while (current) {
|
||||
struct timer_node *temp=current->next;
|
||||
add_node(T,current);
|
||||
current=temp;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
timer_shift(struct timer *T) {
|
||||
LOCK(T);
|
||||
int mask = TIME_NEAR;
|
||||
int time = (++T->time) >> TIME_NEAR_SHIFT;
|
||||
int i=0;
|
||||
|
||||
while ((T->time & (mask-1))==0) {
|
||||
int idx=time & TIME_LEVEL_MASK;
|
||||
if (idx!=0) {
|
||||
--idx;
|
||||
struct timer_node *current = link_clear(&T->t[i][idx]);
|
||||
while (current) {
|
||||
struct timer_node *temp=current->next;
|
||||
add_node(T,current);
|
||||
current=temp;
|
||||
uint32_t ct = ++T->time;
|
||||
if (ct == 0) {
|
||||
move_list(T, 3, 0);
|
||||
} else {
|
||||
uint32_t time = ct >> TIME_NEAR_SHIFT;
|
||||
int i=0;
|
||||
|
||||
while ((ct & (mask-1))==0) {
|
||||
int idx=time & TIME_LEVEL_MASK;
|
||||
if (idx!=0) {
|
||||
move_list(T, i, idx);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
mask <<= TIME_LEVEL_SHIFT;
|
||||
time >>= TIME_LEVEL_SHIFT;
|
||||
++i;
|
||||
}
|
||||
mask <<= TIME_LEVEL_SHIFT;
|
||||
time >>= TIME_LEVEL_SHIFT;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
UNLOCK(T);
|
||||
}
|
||||
|
||||
@@ -187,7 +198,7 @@ timer_create_timer() {
|
||||
}
|
||||
|
||||
for (i=0;i<4;i++) {
|
||||
for (j=0;j<TIME_LEVEL-1;j++) {
|
||||
for (j=0;j<TIME_LEVEL;j++) {
|
||||
link_clear(&r->t[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user