Exemple #1
0
func NewManager(trans, addr string) (*Manager, error) {
	t, err := transport.NewManager(trans)
	if err != nil {
		return nil, err
	}

	mng := &Manager{
		txs:       map[key]Transaction{},
		txLock:    &sync.RWMutex{},
		transport: t,
	}

	mng.requests = make(chan *ServerTransaction, 5)

	// Spin up a goroutine to pull messages up from the depths.
	c := mng.transport.GetChannel()
	go func() {
		for msg := range c {
			go mng.handle(msg)
		}
	}()

	err = mng.transport.Listen(addr)
	if err != nil {
		return nil, err
	}

	return mng, nil
}
Exemple #2
0
func (test *transactionTest) Execute(t *testing.T) {
	defer func() { <-time.After(time.Millisecond * 200) }()
	var err error
	test.client, err = NewManager("udp", c_CLIENT)
	assertNoError(t, err)
	defer test.client.Stop()

	test.server, err = transport.NewManager("udp")
	assertNoError(t, err)
	defer test.server.Stop()
	test.serverRecv = test.server.GetChannel()
	test.server.Listen(c_SERVER)

	for _, actn := range test.actions {
		testLog.Debug("Performing action %v", actn)
		assertNoError(t, actn.Act(test))
	}
}