local cast

This commit is contained in:
云风
2012-10-12 13:45:40 +08:00
parent e8afe6db20
commit 9aeb6f8ed8
6 changed files with 24 additions and 2 deletions

View File

@@ -15,9 +15,11 @@ all : \
service/multicast.so \
service/tunnel.so \
service/harbor.so \
service/localcast.so \
luaclib/skynet.so \
luaclib/socket.so \
luaclib/int64.so \
luaclib/mcast.so \
client
skynet : \
@@ -61,6 +63,9 @@ service/snlua.so : service-src/service_lua.c
service/gate.so : gate/mread.c gate/ringbuffer.c gate/main.c
gcc $(CFLAGS) $(SHARED) $^ -o $@ -Igate -Iskynet-src
service/localcast.so : service-src/service_localcast.c
gcc $(CFLAGS) $(SHARED) $^ -o $@ -Iservice -Iskynet-src
luaclib/skynet.so : lualib-src/lua-skynet.c lualib-src/lua-seri.c lualib-src/lua-remoteobj.c lualib-src/trace_service.c | luaclib
gcc $(CFLAGS) $(SHARED) -Iluacompat $^ -o $@ -Iskynet-src -Ilualib-src
@@ -76,6 +81,9 @@ luaclib/socket.so : connection/lua-socket.c | luaclib
luaclib/int64.so : lua-int64/int64.c | luaclib
gcc $(CFLAGS) $(SHARED) -Iluacompat -O2 $^ -o $@
luaclib/mcast.so : lualib-src/lua-localcast.c | luaclib
gcc $(CFLAGS) $(SHARED) -Iluacompat $^ -o $@ -Iskynet-src -Iservice-src
client : client-src/client.c
gcc $(CFLAGS) $^ -o $@ -lpthread

View File

@@ -1,4 +1,5 @@
local c = require "skynet.c"
local mc = require "mcast.c"
local tostring = tostring
local tonumber = tonumber
local coroutine = coroutine
@@ -175,6 +176,11 @@ function skynet.send(addr, typename, ...)
return c.send(addr, p.id, 0 , p.pack(...))
end
function skynet.cast(group, typename, ...)
local p = proto[typename]
return c.send(".cast", p.id, 0, mc(group, p.pack(...)))
end
skynet.genid = assert(c.genid)
skynet.forward = assert(c.forward)

View File

@@ -5,11 +5,14 @@ local group = require "mcgroup"
skynet.start(function()
local gid = group.create()
local gaddr = group.address(gid)
local g = {}
print("=== Create Group ===",gid,skynet.address(gaddr))
for i=1,10 do
local address = skynet.newservice("testgroup_c", tostring(i))
table.insert(g, address)
group.enter(gid , address)
end
skynet.cast(g,"text","Cast")
skynet.sleep(1000)
skynet.send(gaddr,"text","Hello World")
skynet.exit()

View File

@@ -213,7 +213,7 @@ skynet_multicast_castgroup(struct skynet_context * from, struct skynet_multicast
}
void
skynet_multicast_cast(struct skynet_context * from, struct skynet_multicast_message *msg, uint32_t *dests, int n) {
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);
int i;

View File

@@ -13,7 +13,7 @@ typedef void (*skynet_multicast_func)(void *ud, uint32_t source, const void * ms
struct skynet_multicast_message * skynet_multicast_create(const void * msg, size_t sz, uint32_t source);
void skynet_multicast_copy(struct skynet_multicast_message *, int copy);
void skynet_multicast_dispatch(struct skynet_multicast_message * msg, void * ud, skynet_multicast_func func);
void skynet_multicast_cast(struct skynet_context * from, struct skynet_multicast_message *msg, uint32_t *dests, int n);
void skynet_multicast_cast(struct skynet_context * from, struct skynet_multicast_message *msg, const uint32_t *dests, int n);
struct skynet_multicast_group * skynet_multicast_newgroup();
void skynet_multicast_deletegroup(struct skynet_multicast_group * group);

View File

@@ -118,6 +118,11 @@ skynet_start(struct skynet_config * config) {
fprintf(stderr,"launch logger error");
exit(1);
}
ctx = skynet_context_new("localcast", NULL);
if (ctx == NULL) {
fprintf(stderr,"launch local cast error");
exit(1);
}
ctx = skynet_context_new("snlua", "launcher");
if (ctx) {
ctx = skynet_context_new("snlua", config->start);