예제 #1
0
func StartTestGateway(t *testing.T, backendAddr string) *Frontend {
	listener, err := link.Listen("tcp", "0.0.0.0:0", protocol)
	unitest.NotError(t, err)

	var linkIds []uint64

	gateway := NewFrontend(listener.(*packet.Listener),
		func(_ *link.Session) (uint64, error) {
			return linkIds[rand.Intn(len(linkIds))], nil
		},
	)

	for i := 0; i < 10; i++ {
		id, err := gateway.AddBackend("tcp",
			backendAddr,
			stream.New(1024, 1024, 1024),
		)
		unitest.NotError(t, err)
		linkIds = append(linkIds, id)
	}

	return gateway
}
예제 #2
0
func NewBackend(readBufferSize, writeBufferSize, sendChanSize int) *Backend {
	return &Backend{stream.New(readBufferSize, writeBufferSize, sendChanSize)}
}
예제 #3
0
func New(spliter binary.Spliter, readBufferSize, writeBufferSize, sendChanSize int) *Protocol {
	return &Protocol{stream.New(readBufferSize, writeBufferSize, sendChanSize), spliter, nil, nil}
}