示例#1
0
func writeLoop(cli *client.Client, finish *sync.WaitGroup, ready *sync.WaitGroup) {

	list := cli.List()
	if len(list) > 255 {
		list = list[:255]
	}
	binary := message.NewRelayRequest(list, payload).ToByteArray()
	ready.Wait()

	for i := 0; i < mexNum; i++ {
		cli.SendBytes(binary)
		if showStat {
			allStats.OutgoingMessages.Increase(1)
		}
		time.Sleep(interval)
	}
	finish.Done()
}
示例#2
0
func ForwardAndListen(cli *client.Client) int {

	var received int
	req := message.NewRelayRequest(cli.List(), testBody)
	incoming := cli.IncomingRelay()
	var expectedIncoming int = MessagesPerCLient * (ClientsNum - 1)

	for i := 0; i < MessagesPerCLient; i++ {
		go cli.Send(req)
	}

	for i := 0; i < expectedIncoming; i++ {
		select {
		case <-incoming:
			received++
		case <-time.After(TimeoutTime):
			log.Println(cli.Id(), "timed out")
			return received
		}
	}

	return received

}