Esempio n. 1
0
func newFrontLink(session *link.Session) *frontendLink {
	session.EnableAsyncSend(10000)

	flink := &frontendLink{
		session:     session,
		clients:     make(map[uint64]*link.Session),
		clientWaits: make(map[uint64]*link.Session),
	}

	session.AddCloseCallback(flink, func() {
		flink.Close()
	})

	go func() {
		var msg gatewayMsg
		for {
			if err := session.Receive(&msg); err != nil {
				break
			}
			switch msg.Command {
			case CMD_MSG:
				flink.dispathMsg(msg.ClientId, msg.Data)
			case CMD_BRD:
				flink.broadcast(msg.ClientIds, msg.Data)
			case CMD_NEW_2:
				flink.newClient(msg.ClientId, msg.ClientIds[0])
			case CMD_DEL:
				flink.delClient(msg.ClientId, false)
			}
		}
		flink.Close()
	}()

	return flink
}
Esempio n. 2
0
func newBackendLink(id uint64, listener *BackendListener, session *link.Session) *backendLink {
	session.EnableAsyncSend(10000)
	this := &backendLink{
		id:       id,
		listener: listener,
		session:  session,
		conns:    make(map[uint64]*BackendConn),
	}
	session.AddCloseCallback(this, func() {
		this.Close(false)
	})
	go this.loop()
	return this
}