Skip to content

Commit 081420a

Browse files
committed
add defer connection close
1 parent b52c0db commit 081420a

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

client/server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func proxyToServer(client *Client, serverAddr string) {
2121
eConn := utils.NewEncryptedConn(remoteConn, client.Password)
2222
// remoteConn, err := net.Dial("tcp", "localhost:8112")
2323

24-
defer eConn.Conn.Close()
24+
defer eConn.Close()
2525

2626
go utils.Copy(eConn, client.Conn)
2727
utils.Copy(client.Conn, eConn)
@@ -44,7 +44,6 @@ func handleClient(client *Client, serverAddr string) {
4444
}
4545

4646
method := chooseAuthMethod(methods)
47-
4847
err = client.SetAuthMethod(method)
4948

5049
if err != nil {

server/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
)
88

99
func handleConn(eConn *utils.EncryptedConn) {
10+
defer eConn.Close()
11+
1012
buf := utils.Pool33K.Get()
1113
defer utils.Pool33K.Put(buf)
1214

utils/io.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
"time"
77
)
88

9-
// this code is copy from https://golang.org/src/io/io.go
10-
// add timeout and buffer pool support
9+
// this code is copied from https://golang.org/src/io/io.go
10+
// with some additions
11+
// 1. timeout
12+
// 2. buffer pool
1113

1214
func Copy(dst net.Conn, src net.Conn) (written int64, err error) {
1315
timeoutDuration := 15 * time.Second

0 commit comments

Comments
 (0)