no isclosed

This commit is contained in:
Zack Scholl 2019-04-29 18:55:37 -07:00
parent 6b149480d4
commit a17f3096a0
4 changed files with 2 additions and 19 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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())
}

View File

@ -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