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