forked from TrueCloudLab/neoneo-go
Merge pull request #301 from nspcc-dev/fix-sigsegv-on-failed-bind
connmgr: correctly pass binding error to the server
This commit is contained in:
commit
bb2568cc53
3 changed files with 13 additions and 11 deletions
|
@ -27,7 +27,13 @@ type Connmgr struct {
|
|||
}
|
||||
|
||||
//New creates a new connection manager
|
||||
func New(cfg Config) *Connmgr {
|
||||
func New(cfg Config) (*Connmgr, error) {
|
||||
listener, err := net.Listen("tcp", cfg.AddressPort)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cnnmgr := &Connmgr{
|
||||
cfg,
|
||||
make(map[string]*Request),
|
||||
|
@ -36,13 +42,6 @@ func New(cfg Config) *Connmgr {
|
|||
}
|
||||
|
||||
go func() {
|
||||
|
||||
listener, err := net.Listen("tcp", cfg.AddressPort)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Error connecting to outbound ", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
listener.Close()
|
||||
}()
|
||||
|
@ -59,7 +58,7 @@ func New(cfg Config) *Connmgr {
|
|||
|
||||
}()
|
||||
|
||||
return cnnmgr
|
||||
return cnnmgr, nil
|
||||
}
|
||||
|
||||
// NewRequest will make a new connection gets the address from address func in config
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
iputils "github.com/CityOfZion/neo-go/pkg/wire/util/ip"
|
||||
)
|
||||
|
||||
func setupConnManager(s *Server, port uint16) *connmgr.Connmgr {
|
||||
func setupConnManager(s *Server, port uint16) (*connmgr.Connmgr, error) {
|
||||
cfg := connmgr.Config{
|
||||
GetAddress: s.getAddress,
|
||||
OnAccept: s.onAccept,
|
||||
|
|
|
@ -63,7 +63,10 @@ func New(net protocol.Magic, port uint16) (*Server, error) {
|
|||
s.smg = syncmgr
|
||||
|
||||
// Setup connection manager
|
||||
connmgr := setupConnManager(s, port)
|
||||
connmgr, err := setupConnManager(s, port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.cmg = connmgr
|
||||
|
||||
// Setup peer config
|
||||
|
|
Loading…
Reference in a new issue