Skip to content

Commit

Permalink
simplify dial/listen
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Jul 8, 2019
1 parent 3923bba commit bb6bf99
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 47 deletions.
11 changes: 9 additions & 2 deletions client/dial.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// +build !linux

package main

import (
"github.com/pkg/errors"
kcp "github.com/xtaci/kcp-go"
"github.com/xtaci/tcpraw"
)

func dial(config *Config, block kcp.BlockCrypt) (*kcp.UDPSession, error) {
if config.TCP {
conn, err := tcpraw.Dial("tcp", config.RemoteAddr)
if err != nil {
return nil, errors.Wrap(err, "tcpraw.Dial()")
}
return kcp.NewConn(config.RemoteAddr, block, config.DataShard, config.ParityShard, conn)
}
return kcp.DialWithOptions(config.RemoteAddr, block, config.DataShard, config.ParityShard)
}
20 changes: 0 additions & 20 deletions client/dial_linux.go

This file was deleted.

2 changes: 1 addition & 1 deletion client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func main() {
},
cli.BoolFlag{
Name: "tcp",
Usage: "to emulate a TCP connection",
Usage: "to emulate a TCP connection(linux)",
},
cli.StringFlag{
Name: "c",
Expand Down
15 changes: 12 additions & 3 deletions server/listen.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
// +build !linux

package main

import kcp "github.com/xtaci/kcp-go"
import (
"github.com/pkg/errors"
kcp "github.com/xtaci/kcp-go"
"github.com/xtaci/tcpraw"
)

func listen(config *Config, block kcp.BlockCrypt) (*kcp.Listener, error) {
if config.TCP {
conn, err := tcpraw.Listen("tcp", config.Listen)
if err != nil {
return nil, errors.Wrap(err, "tcpraw.Listen()")
}
return kcp.ServeConn(block, config.DataShard, config.ParityShard, conn)
}
return kcp.ListenWithOptions(config.Listen, block, config.DataShard, config.ParityShard)
}
20 changes: 0 additions & 20 deletions server/listen_linux.go

This file was deleted.

2 changes: 1 addition & 1 deletion server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func main() {
},
cli.BoolFlag{
Name: "tcp",
Usage: "to emulate a TCP connection",
Usage: "to emulate a TCP connection(linux)",
},
cli.StringFlag{
Name: "c",
Expand Down

0 comments on commit bb6bf99

Please sign in to comment.