//Channel base on a service, args[0] is N worker to dispatch msg func New(service *cham.Service, channel uint32, start cham.Start, args ...interface{}) *Channel { multicast = cham.UniqueService("multicast", Start, args...) if channel == 0 { channel = service.Call(multicast, cham.PTYPE_GO, NEW, uint32(0), service.Addr)[0].(uint32) } service.RegisterProtocol(cham.PTYPE_MULTICAST, start) c := &Channel{service, channel} return c }
func Start(service *cham.Service, args ...interface{}) cham.Dispatch { log.Infoln("New Service ", service.String()) gate := New(0, service) return func(session int32, source cham.Address, ptype uint8, args ...interface{}) []interface{} { cmd := args[0].(uint8) result := cham.NORET switch cmd { case OPEN: gate.Source = source service.RegisterProtocol(cham.PTYPE_RESPONSE, ResponseStart, gate) gate.open(args[1].(*Conf)) case KICK: gate.kick(args[1].(uint32)) } return result } }