Skip to content

Commit

Permalink
fix kcp/quic issue of client. Use their tags instead of udp
Browse files Browse the repository at this point in the history
  • Loading branch information
smallnest committed Oct 30, 2017
1 parent 24c716b commit c079990
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ The below is a simple example.
// define example.Arith
โ€ฆโ€ฆ

s := server.Server{}
s := server.NewServer()
s.RegisterName("Arith", new(example.Arith), "")
s.Serve("tcp", addr)

Expand Down
22 changes: 22 additions & 0 deletions client/connection_kcp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// +build kcp

package client

import (
"net"

kcp "github.com/xtaci/kcp-go"
)

func newDirectKCPConn(c *Client, network, address string) (net.Conn, error) {
var conn net.Conn
var err error

conn, err = kcp.DialWithOptions(address, c.option.Block.(kcp.BlockCrypt), 10, 3)

if err != nil {
return nil, err
}

return conn, nil
}
12 changes: 12 additions & 0 deletions client/connection_nonkcp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// +build !kcp

package client

import (
"errors"
"net"
)

func newDirectKCPConn(c *Client, network, address string) (net.Conn, error) {
return nil, errors.New("kcp unsupported")
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !udp
// +build !quic

package client

Expand All @@ -7,10 +7,6 @@ import (
"net"
)

func newDirectKCPConn(c *Client, network, address string) (net.Conn, error) {
return nil, errors.New("kcp unsupported")
}

func newDirectQuicConn(c *Client, network, address string) (net.Conn, error) {
return nil, errors.New("quic unsupported")
}
16 changes: 1 addition & 15 deletions client/connection_udp.go โ†’ client/connection_quic.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build udp
// +build quic

package client

Expand All @@ -7,22 +7,8 @@ import (
"net"

quicconn "github.com/marten-seemann/quic-conn"
kcp "github.com/xtaci/kcp-go"
)

func newDirectKCPConn(c *Client, network, address string) (net.Conn, error) {
var conn net.Conn
var err error

conn, err = kcp.DialWithOptions(address, c.option.Block.(kcp.BlockCrypt), 10, 3)

if err != nil {
return nil, err
}

return conn, nil
}

func newDirectQuicConn(c *Client, network, address string) (net.Conn, error) {
var conn net.Conn
var err error
Expand Down
1 change: 1 addition & 0 deletions client/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (s *roundRobinSelector) Select(ctx context.Context, servicePath, serviceMet
i := s.i
i = i % len(ss)
s.i = i + 1

return ss[i]
}

Expand Down
1 change: 0 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func NewServer(options ...OptionFn) *Server {
}

for _, op := range options {
fmt.Printf("%T\n", op)
op(s)
}

Expand Down

0 comments on commit c079990

Please sign in to comment.