handlers.go 376 Bytes
Newer Older
Jeromy's avatar
Jeromy committed
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
package peerstream

import (
	"io"
	"math/rand"
)

var SelectRandomConn = func(conns []*Conn) *Conn {
	if len(conns) == 0 {
		return nil
	}

	return conns[rand.Intn(len(conns))]
}

func EchoHandler(s *Stream) {
	go func() {
		io.Copy(s, s)
		s.Close()
	}()
}

func CloseHandler(s *Stream) {
	s.Close()
}

func NoOpStreamHandler(s *Stream) {}

func NoOpConnHandler(c *Conn) {}