func readLoop(cli *client.Client, finish *sync.WaitGroup) { for i := 0; i < messagesToRead; i++ { <-cli.IncomingRelay() if showStat { allStats.IncomingMessages.Increase(1) } } finish.Done() }
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() }
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 }