Пример #1
0
//service self
func Start(service *cham.Service, args ...interface{}) cham.Dispatch {
	log.Infoln("New Service ", service.String())
	mul := new(Multicast)
	mul.channel = 0
	mul.groups = make(map[uint32]map[cham.Address]cham.NULL, DEFAULT_GROUP_SIZE)

	return func(session int32, source cham.Address, ptype uint8, args ...interface{}) []interface{} {
		cmd := args[0].(uint8)
		channel := args[1].(uint32)
		addr := args[2].(cham.Address)

		result := cham.NORET

		switch cmd {
		case NEW:
			result = cham.Ret(mul.new(addr))
		case SUB:
			mul.sub(addr, channel)
		case PUB:
			mul.pub(addr, channel, args[3:]...)
		case UNSUB:
			mul.unsub(addr, channel)
		case DEL:
			mul.del(channel)
		}
		return result
	}
}
Пример #2
0
func ResponseStart(service *cham.Service, args ...interface{}) cham.Dispatch {
	gate := args[0].(*Gate)
	return func(session int32, source cham.Address, ptype uint8, args ...interface{}) []interface{} {
		sessionid := args[0].(uint32)
		data := args[1].([]byte)
		err := gate.Write(sessionid, data)
		return cham.Ret(err)
	}
}