1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-24 16:23:47 +03:00

close correctly

This commit is contained in:
Zack Scholl 2018-09-24 16:10:04 -07:00
parent 7df06272b8
commit 44fad198e7
3 changed files with 9 additions and 3 deletions

View File

@ -27,6 +27,12 @@ func (c Comm) Connection() net.Conn {
return c.connection
}
// Close closes the connection
func (c Comm) Close() {
c.connection.Close()
}
func (c Comm) Write(b []byte) (int, error) {
c.connection.Write([]byte(fmt.Sprintf("%0.5d", len(b))))
n, err := c.connection.Write(b)

View File

@ -178,6 +178,7 @@ func receive(forceSend int, serverAddress, serverTCP string, isLocal bool, c *we
log.Error(err)
return err
}
defer tcpConnection.Close()
}
// await file
@ -329,7 +330,6 @@ func connectToTCPServer(room string, address string) (com comm.Comm, err error)
if err != nil {
return
}
defer connection.Close()
connection.SetReadDeadline(time.Now().Add(3 * time.Hour))
connection.SetDeadline(time.Now().Add(3 * time.Hour))
connection.SetWriteDeadline(time.Now().Add(3 * time.Hour))

View File

@ -211,6 +211,7 @@ func send(forceSend int, serverAddress, serverTCP string, isLocal bool, c *webso
log.Error(err)
return
}
defer tcpConnection.Close()
buffer = make([]byte, models.TCP_BUFFER_SIZE/2)
}
@ -306,11 +307,10 @@ func connectToTCPServer(room string, address string) (com comm.Comm, err error)
if err != nil {
return
}
defer connection.Close()
connection.SetReadDeadline(time.Now().Add(3 * time.Hour))
connection.SetDeadline(time.Now().Add(3 * time.Hour))
connection.SetWriteDeadline(time.Now().Add(3 * time.Hour))
com = comm.New(connection)
ok, err := com.Receive()
if err != nil {