Example #1
0
func client(initWait *sync.WaitGroup, conn *CountConn, startChan chan int, timeout time.Time, msg []byte) {
	client := link.NewSession(conn, link.Bufio(link.Bytes(link.Uint16BE)))

	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()
}
Example #2
0
func Test_Bufio_SelfCodec(t *testing.T) {
	SessionTest(t, link.Bufio(SelfCodec()), ObjectTest)
}
Example #3
0
func Test_Bufio_Packet_SelfCodec(t *testing.T) {
	SessionTest(t, link.Bufio(Packet(Uint16BE, SelfCodec())), ObjectTest)
}
Example #4
0
func Test_Bufio_Packet_Xml(t *testing.T) {
	SessionTest(t, link.Bufio(Packet(Uint16BE, link.Xml())), ObjectTest)
}
Example #5
0
func Test_Bufio_Packet_String(t *testing.T) {
	SessionTest(t, link.Bufio(Packet(Uint16BE, String(Uint16BE))), StringTest)
}
Example #6
0
func Test_Bufio_String(t *testing.T) {
	SessionTest(t, link.Bufio(String(Uint16BE)), StringTest)
}
Example #7
0
func Test_Bufio_Packet_Bytes(t *testing.T) {
	SessionTest(t, link.Bufio(Packet(Uint16BE, Bytes(Uint16BE))), BytesTest)
}
Example #8
0
func Test_Bufio_Bytes(t *testing.T) {
	SessionTest(t, link.Bufio(Bytes(Uint16BE)), BytesTest)
}