Skip to content

Commit

Permalink
fixes nanomsg#33 Kill off the impl.pipe.IsOpen
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Oct 30, 2018
1 parent a700d83 commit 62c3b5f
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 62 deletions.
4 changes: 0 additions & 4 deletions impl/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ func (p *pipe) GetOption(name string) (interface{}, error) {
return val, err
}

func (p *pipe) IsOpen() bool {
return p.p.IsOpen()
}

func (p *pipe) Dialer() mangos.Dialer {
if p.d == nil {
return nil
Expand Down
13 changes: 2 additions & 11 deletions test/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ func (tt *TranTest) TestListenAndAccept(t *testing.T) {
}
t.Logf("Connected client: %d (server %d)",
client.LocalProtocol(), client.RemoteProtocol())
t.Logf("Client open: %t", client.IsOpen())
if !client.IsOpen() {
t.Error("Client is closed")
return
}
}()

server, err := l.Accept()
Expand All @@ -130,10 +125,6 @@ func (tt *TranTest) TestListenAndAccept(t *testing.T) {

t.Logf("Connected server: %d (client %d)",
server.LocalProtocol(), server.RemoteProtocol())
t.Logf("Server open: %t", server.IsOpen())
if !server.IsOpen() {
t.Error("Server is closed")
}
wg.Wait()
}

Expand Down Expand Up @@ -245,7 +236,7 @@ func (tt *TranTest) TestSendRecv(t *testing.T) {
t.Errorf("Dial failed: %v", err)
return
}
t.Logf("Connected client: %t", client.IsOpen())
t.Logf("Connected client")
defer client.Close()

req := mangos.NewMessage(len(ping))
Expand Down Expand Up @@ -290,7 +281,7 @@ func (tt *TranTest) TestSendRecv(t *testing.T) {
t.Errorf("Accept failed: %v", err)
return
}
t.Logf("Connected server: %t", server.IsOpen())
t.Logf("Connected server")
defer server.Close()

// Now we can try to send and receive
Expand Down
3 changes: 0 additions & 3 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ type TranPipe interface {
// connection establishment.
RemoteProtocol() uint16

// IsOpen returns true if the underlying connection is open.
IsOpen() bool

// GetOption returns an arbitrary transport specific option on a
// pipe. Options for pipes are read-only and specific to that
// particular connection. If the property doesn't exist, then
Expand Down
7 changes: 1 addition & 6 deletions transport/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,13 @@ func (p *conn) RemoteProtocol() uint16 {
func (p *conn) Close() error {
p.Lock()
defer p.Unlock()
if p.IsOpen() {
if p.open {
p.open = false
return p.c.Close()
}
return nil
}

// IsOpen implements the Pipe IsOpen method.
func (p *conn) IsOpen() bool {
return p.open
}

func (p *conn) GetOption(n string) (interface{}, error) {
if v, ok := p.options[n]; ok {
return v, nil
Expand Down
15 changes: 4 additions & 11 deletions transport/inproc/inproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,13 @@ func (p *inproc) RemoteProtocol() uint16 {

func (p *inproc) Close() error {
p.Lock()
defer p.Unlock()
if p.IsOpen() {
close(p.closeq)
}
return nil
}

func (p *inproc) IsOpen() bool {
select {
case <-p.closeq:
return false
case <-p.closeq: // If already closed, don't do it again.
default:
return true
close(p.closeq)
}
p.Unlock()
return nil
}

func (p *inproc) GetOption(name string) (interface{}, error) {
Expand Down
23 changes: 1 addition & 22 deletions transport/tcp/tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ func TestTCPListenAndAccept(t *testing.T) {
}
t.Logf("Connected client: %d (server %d)",
client.LocalProtocol(), client.RemoteProtocol())
t.Logf("Client open: %t", client.IsOpen())
if !client.IsOpen() {
t.Error("Client is closed")
return
}
}()

server, err := l.Accept()
Expand All @@ -72,11 +67,6 @@ func TestTCPListenAndAccept(t *testing.T) {

t.Logf("Connected server: %d (client %d)",
server.LocalProtocol(), server.RemoteProtocol())
t.Logf("Server open: %t", server.IsOpen())
if !server.IsOpen() {
t.Error("Server is closed")
return
}
}

func TestTCPAnonymousPort(t *testing.T) {
Expand Down Expand Up @@ -109,11 +99,6 @@ func TestTCPAnonymousPort(t *testing.T) {
}
t.Logf("Connected client: %d (server %d)",
client.LocalProtocol(), client.RemoteProtocol())
t.Logf("Client open: %t", client.IsOpen())
if !client.IsOpen() {
t.Error("Client is closed")
return
}
}()

server, err := l.Accept()
Expand All @@ -125,11 +110,6 @@ func TestTCPAnonymousPort(t *testing.T) {

t.Logf("Connected server: %d (client %d)",
server.LocalProtocol(), server.RemoteProtocol())
t.Logf("Server open: %t", server.IsOpen())
if !server.IsOpen() {
t.Error("Server is closed")
return
}
}

func TestTCPDuplicateListen(t *testing.T) {
Expand Down Expand Up @@ -206,7 +186,7 @@ func TestTCPSendRecv(t *testing.T) {
t.Errorf("Dial failed: %v", err)
return
}
t.Logf("Connected client: %t", client.IsOpen())
t.Logf("Connected client")
defer client.Close()

req := mangos.NewMessage(len(ping))
Expand Down Expand Up @@ -251,7 +231,6 @@ func TestTCPSendRecv(t *testing.T) {
t.Errorf("Accept failed: %v", err)
return
}
t.Logf("Connected server: %t", server.IsOpen())
defer server.Close()

// Now we can try to send and receive
Expand Down
6 changes: 1 addition & 5 deletions transport/ws/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,14 @@ func (w *wsPipe) RemoteProtocol() uint16 {
func (w *wsPipe) Close() error {
w.Lock()
defer w.Unlock()
if w.IsOpen() {
if w.open {
w.open = false
w.ws.Close()
w.wg.Done()
}
return nil
}

func (w *wsPipe) IsOpen() bool {
return w.open
}

func (w *wsPipe) GetOption(name string) (interface{}, error) {
if v, ok := w.options[name]; ok {
return v, nil
Expand Down

0 comments on commit 62c3b5f

Please sign in to comment.