|
|
@@ -7,6 +7,9 @@ import (
|
|
7
|
7
|
)
|
|
8
|
8
|
|
|
9
|
9
|
func Relay(ctx context.Context, log Logger, telegramConn, clientConn net.Conn) {
|
|
|
10
|
+ defer telegramConn.Close()
|
|
|
11
|
+ defer clientConn.Close()
|
|
|
12
|
+
|
|
10
|
13
|
ctx, cancel := context.WithCancel(ctx)
|
|
11
|
14
|
defer cancel()
|
|
12
|
15
|
|
|
|
@@ -28,13 +31,12 @@ func Relay(ctx context.Context, log Logger, telegramConn, clientConn net.Conn) {
|
|
28
|
31
|
|
|
29
|
32
|
func pump(log Logger, src, dst net.Conn, wg *sync.WaitGroup, direction string) {
|
|
30
|
33
|
defer wg.Done()
|
|
31
|
|
- defer src.Close()
|
|
32
|
|
- defer dst.Close()
|
|
33
|
34
|
|
|
34
|
35
|
syncer := acquireSyncPair(src, dst)
|
|
35
|
36
|
defer releaseSyncPair(syncer)
|
|
|
37
|
+ defer syncer.Flush()
|
|
36
|
38
|
|
|
37
|
39
|
if n, err := syncer.Sync(); err != nil {
|
|
38
|
|
- log.Printf("cannot pump %s (written %d bytes): %w", direction, n, err)
|
|
|
40
|
+ log.Printf("cannot pump %s (written %d bytes): %v", direction, n, err)
|
|
39
|
41
|
}
|
|
40
|
42
|
}
|