Пример #1
0
func TestCodec(t *testing.T) {

	// Transport
	f := trace.NewFrame()
	// Carrier
	sx := sandbox.NewUnreliableTransport(f.Refine("sandbox"), 5, 0, time.Second/3, time.Second/3)
	// Chain
	hx := chain.NewTransport(f.Refine("chain"), sx)
	// Faithful
	fx := faithful.NewTransport(f.Refine("faithful"), hx)
	// Codec
	cx := codec.NewTransport(fx, codec.GobCodec{})
	// Blend
	bx := NewTransport(f.Refine("blend"), cx)

	// Sync
	ya, yb := make(chan int), make(chan int)

	// Accepter
	l := bx.Listen(sandbox.Addr("@"))
	for i := 0; i < testN; i++ {
		go testAcceptConn(t, l, ya, yb)
	}

	// Dialer
	for i := 0; i < testN; i++ {
		go testDialConn(t, bx, ya, yb)
	}
	for i := 0; i < testN; i++ {
		<-yb
	}
}
Пример #2
0
func NewStructOverTCP() *blend.Transport {
	f := trace.NewFrame()
	// Carrier
	x0 := tcp.Transport
	// Chain
	x1 := chain.NewTransport(f.Refine("chain"), x0)
	// Faithful
	x2 := faithful.NewTransport(f.Refine("faithful"), x1)
	// Codec
	x3 := codec.NewTransport(x2, codec.GobCodec{})
	// Blend
	return blend.NewTransport(f.Refine("blend"), x3)
}