forked from st3v/go-plugins
/
utp.go
51 lines (43 loc) · 880 Bytes
/
utp.go
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
47
48
49
50
51
// Package utp implements a utp transport
package utp
import (
"bufio"
"encoding/gob"
"net"
"time"
"github.com/micro/go-micro/cmd"
"github.com/micro/go-micro/transport"
)
type utpTransport struct {
opts transport.Options
}
type utpListener struct {
t time.Duration
l net.Listener
opts transport.ListenOptions
}
type utpClient struct {
dialOpts transport.DialOptions
conn net.Conn
enc *gob.Encoder
dec *gob.Decoder
encBuf *bufio.Writer
timeout time.Duration
}
type utpSocket struct {
conn net.Conn
enc *gob.Encoder
dec *gob.Decoder
encBuf *bufio.Writer
timeout time.Duration
}
func init() {
cmd.DefaultTransports["utp"] = NewTransport
}
func NewTransport(opts ...transport.Option) transport.Transport {
var options transport.Options
for _, o := range opts {
o(&options)
}
return &utpTransport{opts: options}
}