int skynet_multicast_castgroup(struct skynet_context * from, struct skynet_multicast_group * group, struct skynet_multicast_message *msg) { combine_queue(from, group); int release = 0; if (group->number > 0) { uint32_t source = skynet_context_handle(from); skynet_multicast_copy(msg, group->number); int i; for (i=0;i<group->number;i++) { uint32_t p = group->data[i]; struct skynet_context * ctx = skynet_handle_grab(p); if (ctx) { skynet_context_send(ctx, msg, 0 , source, PTYPE_MULTICAST , 0); skynet_context_release(ctx); } else { skynet_multicast_leavegroup(group, p); ++release; } } } skynet_multicast_copy(msg, -release); return group->number - release; }
void skynet_harbor_send(struct remote_message *rmsg, uint32_t source, int session) { int type = (int)rmsg->sz >> HANDLE_REMOTE_SHIFT; rmsg->sz &= HANDLE_MASK; assert(type != PTYPE_SYSTEM && type != PTYPE_HARBOR); skynet_context_send(REMOTE, rmsg, sizeof(*rmsg) , source, type , session); }
int skynet_multicast_castgroup(struct skynet_context * from, struct skynet_multicast_group * group, struct skynet_multicast_message *msg) { combine_queue(from, group); if (group->number == 0) { skynet_multicast_dispatch(msg, NULL, NULL); return 0; } uint32_t source = skynet_context_handle(from); skynet_multicast_copy(msg, group->number); int i; int release = 0; for (i=0;i<group->number;i++) { struct pair * p = &group->data[i]; skynet_context_send(p->ctx, msg, 0 , source, PTYPE_MULTICAST , 0); int ref = skynet_context_ref(p->ctx); if (ref == 1) { skynet_context_release(p->ctx); struct skynet_context * ctx = skynet_handle_grab(p->handle); if (ctx == NULL) { p->ctx = NULL; skynet_multicast_leavegroup(group, p->handle); ++release; } } } return group->number - release; }
void skynet_harbor_register(struct remote_name *rname) { int i; int number = 1; for (i=0;i<GLOBALNAME_LENGTH;i++) { char c = rname->name[i]; if (!(c >= '0' && c <='9')) { number = 0; break; } } assert(number == 0); skynet_context_send(REMOTE, rname, sizeof(*rname), 0, PTYPE_SYSTEM , 0); }
void skynet_multicast_cast(struct skynet_context * from, struct skynet_multicast_message *msg, const uint32_t *dests, int n) { uint32_t source = skynet_context_handle(from); skynet_multicast_copy(msg, n); if (n == 0) return; int i; int release = 0; for (i=0;i<n;i++) { uint32_t p = dests[i]; struct skynet_context * ctx = skynet_handle_grab(p); if (ctx) { skynet_context_send(ctx, msg, 0 , source, PTYPE_MULTICAST , 0); skynet_context_release(ctx); } else { ++release; } } skynet_multicast_copy(msg, -release); }
void skynet_group_clear(int handle) { struct group *g = _G; _lock(g); int hash = handle % HASH_SIZE; struct group_node ** pnode = &g->node[hash]; while (*pnode) { struct group_node * node = *pnode; if (node->handle == handle) { struct skynet_context * ctx = node->ctx; char * cmd = malloc(8); int n = sprintf(cmd, "C"); skynet_context_send(ctx, cmd, n+1, 0 , PTYPE_SYSTEM, 0); *pnode = node->next; free(node); break; } pnode = &node->next; } _unlock(g); }
static void send_command(struct skynet_context *ctx, const char * cmd, uint32_t node) { char * tmp = malloc(16); int n = sprintf(tmp, "%s %x", cmd, node); skynet_context_send(ctx, tmp, n+1 , 0, PTYPE_SYSTEM, 0); }