Skip to content

Commit

Permalink
fixes nanomsg#25 Port IsClient/IsServer redundant?
Browse files Browse the repository at this point in the history
fixes nanomsg#26 Port RemoteProtocol and LocalProtocol are mostly useless
  • Loading branch information
gdamore committed Oct 30, 2018
1 parent 3cf085c commit 760ba34
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 32 deletions.
22 changes: 6 additions & 16 deletions impl/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,16 @@ func (p *pipe) IsOpen() bool {
return p.p.IsOpen()
}

func (p *pipe) IsClient() bool {
return p.d != nil
}

func (p *pipe) IsServer() bool {
return p.l != nil
}

func (p *pipe) LocalProtocol() uint16 {
return p.p.LocalProtocol()
}

func (p *pipe) RemoteProtocol() uint16 {
return p.p.RemoteProtocol()
}

func (p *pipe) Dialer() mangos.Dialer {
if p.d == nil {
return nil
}
return p.d
}

func (p *pipe) Listener() mangos.Listener {
if p.l == nil {
return nil
}
return p.l
}
12 changes: 0 additions & 12 deletions port.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ type Port interface {
// Note that if a dialer is present and active, it will redial.
Close() error

// IsServer returns true if the connection is from a server (Listen).
IsServer() bool

// IsClient returns true if the connection is from a client (Dial).
IsClient() bool

// LocalProtocol returns the local protocol number.
LocalProtocol() uint16

// RemoteProtocol returns the remote protocol number.
RemoteProtocol() uint16

// Dialer returns the dialer for this Port, or nil if a server.
Dialer() Dialer

Expand Down
4 changes: 2 additions & 2 deletions test/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ func (c *T) RecvStart() bool {
c.Errorf("Got unexpected message port address: %s", addr)
return false
}
if c.IsServer() && !m.Port.IsServer() {
if c.IsServer() && m.Port.Listener() == nil {
c.Errorf("Expected message port server")
return false
}
if !c.IsServer() && !m.Port.IsClient() {
if !c.IsServer() && m.Port.Dialer() == nil {
c.Errorf("Expected message port client")
return false
}
Expand Down
9 changes: 7 additions & 2 deletions test/porthook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ type hooktest struct {
}

func (h *hooktest) Hook(action mangos.PortAction, p mangos.Port) bool {
h.t.Logf("Hook called - %v!", action)
i := hookinfo{action: action, addr: p.Address(), isopen: p.IsOpen(), server: p.IsServer()}
h.t.Logf("Hook called - %v", action)
i := hookinfo{
action: action,
addr: p.Address(),
isopen: p.IsOpen(),
server: p.Listener() != nil,
}
h.Lock()
h.calls = append(h.calls, i)
h.Unlock()
Expand Down

0 comments on commit 760ba34

Please sign in to comment.