From a17f3096a0f449d7bab0408d8dc4abf8e7134b03 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Mon, 29 Apr 2019 18:55:37 -0700 Subject: [PATCH] no isclosed --- src/comm/comm.go | 15 --------------- src/comm/comm_test.go | 2 +- src/tcp/tcp_test.go | 2 -- src/utils/utils_test.go | 2 +- 4 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/comm/comm.go b/src/comm/comm.go index 7e11989..70c4a8a 100644 --- a/src/comm/comm.go +++ b/src/comm/comm.go @@ -15,21 +15,6 @@ type Comm struct { connection net.Conn } -func (c *Comm) IsClosed() bool { - one := []byte{} - c.connection.SetReadDeadline(time.Now()) - _, err := c.connection.Read(one) - if err != nil { - fmt.Println(err) - c.connection.Close() - c.connection = nil - return true - } else { - c.connection.SetReadDeadline(time.Now().Add(3 * time.Hour)) - } - return false -} - // NewConnection gets a new comm to a tcp address func NewConnection(address string) (c *Comm, err error) { connection, err := net.DialTimeout("tcp", address, 3*time.Second) diff --git a/src/comm/comm_test.go b/src/comm/comm_test.go index 207b231..5db5f1a 100644 --- a/src/comm/comm_test.go +++ b/src/comm/comm_test.go @@ -47,7 +47,7 @@ func TestComm(t *testing.T) { } }() - time.Sleep(100 * time.Millisecond) + time.Sleep(300 * time.Millisecond) a, err := NewConnection("localhost:" + port) assert.Nil(t, err) data, err := a.Receive() diff --git a/src/tcp/tcp_test.go b/src/tcp/tcp_test.go index 1a75ae4..73f2a94 100644 --- a/src/tcp/tcp_test.go +++ b/src/tcp/tcp_test.go @@ -17,7 +17,6 @@ func TestTCP(t *testing.T) { _, err = ConnectToTCPServer("localhost:8081", "testRoom") assert.NotNil(t, err) - assert.False(t, c1.IsClosed()) // try sending data assert.Nil(t, c1.Send([]byte("hello, c2"))) data, err := c2.Receive() @@ -30,5 +29,4 @@ func TestTCP(t *testing.T) { assert.Equal(t, []byte("hello, c1"), data) c1.Close() - assert.True(t, c1.IsClosed()) } diff --git a/src/utils/utils_test.go b/src/utils/utils_test.go index 2d4d9c4..2b8ab8e 100644 --- a/src/utils/utils_test.go +++ b/src/utils/utils_test.go @@ -16,7 +16,7 @@ func TestExists(t *testing.T) { func TestHashFile(t *testing.T) { b, err := HashFile("utils.go") assert.Nil(t, err) - assert.Equal(t, "33303e23c9c5e9c194d50b399391754e", fmt.Sprintf("%x", b)) + assert.Equal(t, "9a66e5c18b9759073666953da376c037", fmt.Sprintf("%x", b)) } // SHA256 returns sha256 sum