1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
// Copyright 2013 Joe Walnes and the websocketd team.
// All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libwebsocketd
type Endpoint interface {
StartReading()
Terminate()
Output() chan []byte
Send([]byte) bool
}
func PipeEndpoints(e1, e2 Endpoint) {
e1.StartReading()
e2.StartReading()
defer e1.Terminate()
defer e2.Terminate()
for {
select {
case msgOne, ok := <-e1.Output():
if !ok || !e2.Send(msgOne) {
return
}
case msgTwo, ok := <-e2.Output():
if !ok || !e1.Send(msgTwo) {
return
}
}
}
}
|