Skip to content

Commit

Permalink
fix: fix compilation failure on stub platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Jun 7, 2020
1 parent b5fbbda commit b9d8094
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
6 changes: 4 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package gnet
import "errors"

var (
// ErrProtocolNotSupported occurs when trying to use protocol that is not supported.
ErrProtocolNotSupported = errors.New("not supported protocol on this platform")
// ErrUnsupportedProtocol occurs when trying to use protocol that is not supported.
ErrUnsupportedProtocol = errors.New("unsupported protocol on this platform")
// ErrUnsupportedPlatform occurs when running gnet on an unsupported platform.
ErrUnsupportedPlatform = errors.New("unsupported platform in gnet")

// errServerShutdown occurs when server is closing.
errServerShutdown = errors.New("server is going to be shutdown")
Expand Down
4 changes: 2 additions & 2 deletions gnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func Serve(eventHandler EventHandler, addr string, opts ...Option) (err error) {
case "unix":
sniffErrorAndLog(os.RemoveAll(ln.addr))
if runtime.GOOS == "windows" {
err = ErrProtocolNotSupported
err = ErrUnsupportedProtocol
break
}
fallthrough
Expand All @@ -262,7 +262,7 @@ func Serve(eventHandler EventHandler, addr string, opts ...Option) (err error) {
ln.ln, err = net.Listen(ln.network, ln.addr)
}
default:
err = ErrProtocolNotSupported
err = ErrUnsupportedProtocol
}
if err != nil {
return
Expand Down
2 changes: 1 addition & 1 deletion gnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func startClient(network, addr string, multicore, async bool) {
}

func must(err error) {
if err != nil && err != ErrProtocolNotSupported {
if err != nil && err != ErrUnsupportedProtocol {
panic(err)
}
}
Expand Down
37 changes: 20 additions & 17 deletions server_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,30 @@

package gnet

import (
"errors"
"os"
)
import "net"

func (ln *listener) close() {
if ln.ln != nil {
ln.ln.Close()
}
if ln.pconn != nil {
ln.pconn.Close()
}
if ln.network == "unix" {
os.RemoveAll(ln.addr)
}
type server struct {
subEventLoopSet loadBalancer // event-loops for handling events
}

type eventloop struct {
connCount int32 // number of active connections in event-loop
}

type listener struct {
ln net.Listener
pconn net.PacketConn
lnaddr net.Addr
addr, network string
}

func (ln *listener) system() error {
func (ln *listener) renormalize() error {
return nil
}

func serve(eventHandler EventHandler, listeners []*listener) error {
return errors.New("Unsupported platform in gnet")
func (ln *listener) close() {
}

func serve(eventHandler EventHandler, listeners *listener, options *Options) error {
return ErrUnsupportedPlatform
}

0 comments on commit b9d8094

Please sign in to comment.