Skip to content

Commit

Permalink
fix: supplement all the formal protocol formats of TCP and UDP
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Jun 6, 2020
1 parent 7862f3e commit 258253c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions gnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func Serve(eventHandler EventHandler, addr string, opts ...Option) (err error) {

ln.network, ln.addr = parseAddr(addr)
switch ln.network {
case "udp":
case "udp", "udp4", "udp6":
if options.ReusePort {
ln.pconn, err = netpoll.ReusePortListenPacket(ln.network, ln.addr)
} else {
Expand All @@ -254,7 +254,7 @@ func Serve(eventHandler EventHandler, addr string, opts ...Option) (err error) {
break
}
fallthrough
case "tcp":
case "tcp", "tcp4", "tcp6":
if options.ReusePort {
ln.ln, err = netpoll.ReusePortListen(ln.network, ln.addr)
} else {
Expand Down Expand Up @@ -282,7 +282,7 @@ func Serve(eventHandler EventHandler, addr string, opts ...Option) (err error) {

func parseAddr(addr string) (network, address string) {
network = "tcp"
address = addr
address = strings.ToLower(addr)
if strings.Contains(address, "://") {
pair := strings.Split(address, "://")
network = pair[0]
Expand Down
4 changes: 2 additions & 2 deletions gnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ func TestDefaultGnetServer(t *testing.T) {
}

func TestTick(t *testing.T) {
testTick("tcp", ":9991", t)
testTick("tcp4", ":9991", t)
}

type testTickServer struct {
Expand Down Expand Up @@ -885,7 +885,7 @@ func testShutdownActionOnOpen(network, addr string) {
}

func TestUDPShutdown(t *testing.T) {
testUDPShutdown("udp", ":9000")
testUDPShutdown("udp4", ":9000")
}

type testUDPShutdownServer struct {
Expand Down

0 comments on commit 258253c

Please sign in to comment.