summaryrefslogtreecommitdiff
path: root/pkg/server/socket/loop.go
blob: c442140a3e2f1c973708436076507a4b963c92eb (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
package socket

import (
	"tunnel/pkg/server/env"
	"tunnel/pkg/server/queue"
)

type loopSocket struct{}

type loopConn struct {
	c chan queue.Q
	q chan error
}

func (c *loopConn) Send(wq queue.Q) error {
	c.c <- wq
	return <-c.q
}

func (c *loopConn) Recv(rq queue.Q) error {
	defer close(c.q)
	return queue.Copy(rq, <-c.c)
}

func (c *loopConn) String() string {
	return "loop"
}

func (c *loopConn) Close() error {
	return nil
}

func (s *loopSocket) New(env.Env) (Conn, error) {
	return &loopConn{make(chan queue.Q), make(chan error)}, nil
}

func (s *loopSocket) String() string {
	return "loop"
}

func (s *loopSocket) Close() {
}

func init() {
	register("loop", loopSocket{})
}