func client(initWait *sync.WaitGroup, conn *CountConn, startChan chan int, timeout time.Time, msg packet.RAW) {
	client := link.NewSession(0, packet.NewConn(conn, packet.New(
		binary.SplitByUint16BE, 1024, 1024, 1024,
	)))

	var wg sync.WaitGroup

	wg.Add(1)
	go func() {
		defer wg.Done()
		initWait.Done()
		<-startChan

		for {
			outMsg := msg
			if *randsize {
				outMsg = packet.RAW(make([]byte, rand.Intn(*messageSize)))
			}
			if err := client.Send(outMsg); err != nil {
				if timeout.After(time.Now()) {
					println("send error:", err.Error())
				}
				break
			}
			atomic.AddUint32(&conn.SendCount, 1)
		}
	}()

	wg.Add(1)
	go func() {
		defer wg.Done()
		initWait.Done()
		<-startChan

		var inMsg packet.RAW
		for {
			if err := client.Receive(&inMsg); err != nil {
				if timeout.After(time.Now()) {
					println("recv error:", err.Error())
				}
				break
			}
			atomic.AddUint32(&conn.RecvCount, 1)
		}
	}()

	wg.Wait()
}
Beispiel #2
0
func client(initWait *sync.WaitGroup, conn *CountConn, startChan chan int, timeout time.Time, msg []byte) {
	pConn, _ := link.Packet(link.Uint16BE).NewClientConn(conn)
	client := link.NewSession(pConn, link.Bytes())

	var wg sync.WaitGroup

	wg.Add(1)
	go func() {
		defer wg.Done()
		initWait.Done()
		<-startChan

		for {
			outMsg := msg
			if *randsize {
				outMsg = make([]byte, rand.Intn(*messageSize))
			}
			if err := client.Send(outMsg); err != nil {
				if timeout.After(time.Now()) {
					println("send error:", err.Error())
				}
				break
			}
			atomic.AddUint32(&conn.SendCount, 1)
		}
	}()

	wg.Add(1)
	go func() {
		defer wg.Done()
		initWait.Done()
		<-startChan

		var inMsg []byte
		for {
			if err := client.Receive(&inMsg); err != nil {
				if timeout.After(time.Now()) {
					println("recv error:", err.Error())
				}
				break
			}
			atomic.AddUint32(&conn.RecvCount, 1)
		}
	}()

	wg.Wait()
}
Beispiel #3
0
func client(initWait *sync.WaitGroup, conn *CountConn, startChan chan int, timeout time.Time, msg []byte) {
	client := link.NewSession(conn, link.Packet(2, *messageSize, 4096, binary.LittleEndian, TestCodec{}))

	var wg sync.WaitGroup

	wg.Add(1)
	go func() {
		defer wg.Done()
		initWait.Done()
		<-startChan

		for {
			outMsg := msg
			if *randsize {
				outMsg = msg[:rand.Intn(*messageSize)]
			}
			if err := client.Send(outMsg); err != nil {
				if timeout.After(time.Now()) {
					println("send error:", err.Error())
				}
				break
			}
			atomic.AddUint32(&conn.SendCount, 1)
		}
	}()

	wg.Add(1)
	go func() {
		defer wg.Done()
		initWait.Done()
		<-startChan

		var inMsg []byte
		for {
			if err := client.Receive(&inMsg); err != nil {
				if timeout.After(time.Now()) {
					println("recv error:", err.Error())
				}
				break
			}
			atomic.AddUint32(&conn.RecvCount, 1)
		}
	}()

	wg.Wait()
}