From 62c3b5f1daf6ba65ad49d36a7e2fe57498121685 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 29 Oct 2018 23:42:31 -0700 Subject: [PATCH] fixes #33 Kill off the impl.pipe.IsOpen --- impl/pipe.go | 4 ---- test/transport.go | 13 ++----------- transport.go | 3 --- transport/conn.go | 7 +------ transport/inproc/inproc.go | 15 ++++----------- transport/tcp/tcp_test.go | 23 +---------------------- transport/ws/ws.go | 6 +----- 7 files changed, 9 insertions(+), 62 deletions(-) diff --git a/impl/pipe.go b/impl/pipe.go index d2a52ce10..bbe87a09d 100644 --- a/impl/pipe.go +++ b/impl/pipe.go @@ -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 diff --git a/test/transport.go b/test/transport.go index f09a39375..a7e605395 100644 --- a/test/transport.go +++ b/test/transport.go @@ -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() @@ -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() } @@ -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)) @@ -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 diff --git a/transport.go b/transport.go index 77c442a82..54c62c444 100644 --- a/transport.go +++ b/transport.go @@ -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 diff --git a/transport/conn.go b/transport/conn.go index f1c5b8e22..9b1998e49 100644 --- a/transport/conn.go +++ b/transport/conn.go @@ -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 diff --git a/transport/inproc/inproc.go b/transport/inproc/inproc.go index f85c2f3ea..4c3144391 100644 --- a/transport/inproc/inproc.go +++ b/transport/inproc/inproc.go @@ -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) { diff --git a/transport/tcp/tcp_test.go b/transport/tcp/tcp_test.go index 0d9ed6bff..9a12ae006 100644 --- a/transport/tcp/tcp_test.go +++ b/transport/tcp/tcp_test.go @@ -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() @@ -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) { @@ -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() @@ -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) { @@ -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)) @@ -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 diff --git a/transport/ws/ws.go b/transport/ws/ws.go index 8da7e5d63..06f85d0fd 100644 --- a/transport/ws/ws.go +++ b/transport/ws/ws.go @@ -172,7 +172,7 @@ 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() @@ -180,10 +180,6 @@ func (w *wsPipe) Close() error { 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