Просмотр исходного кода

Refactor timeoutrwc to wrappers

tags/0.9
9seconds 8 лет назад
Родитель
Сommit
c92a4b8c68
2 измененных файлов: 2 добавлений и 42 удалений
  1. 2
    2
      proxy/server.go
  2. 0
    40
      proxy/timeoutrwc.go

+ 2
- 2
proxy/server.go Просмотреть файл

@@ -112,7 +112,7 @@ func (s *Server) makeSocketID() string {
112 112
 }
113 113
 
114 114
 func (s *Server) getClientStream(ctx context.Context, cancel context.CancelFunc, conn net.Conn, socketID string) (io.ReadWriteCloser, int16, error) {
115
-	wConn := newTimeoutReadWriteCloser(conn, s.readTimeout, s.writeTimeout)
115
+	wConn := wrappers.NewTimeoutRWC(conn, s.readTimeout, s.writeTimeout)
116 116
 	wConn = newTrafficReadWriteCloser(wConn, s.stats.addIncomingTraffic, s.stats.addOutgoingTraffic)
117 117
 	frame, err := obfuscated2.ExtractFrame(wConn)
118 118
 	if err != nil {
@@ -136,7 +136,7 @@ func (s *Server) getTelegramStream(ctx context.Context, cancel context.CancelFun
136 136
 	if err != nil {
137 137
 		return nil, errors.Annotate(err, "Cannot dial")
138 138
 	}
139
-	wConn := newTimeoutReadWriteCloser(socket, s.readTimeout, s.writeTimeout)
139
+	wConn := wrappers.NewTimeoutRWC(socket, s.readTimeout, s.writeTimeout)
140 140
 	wConn = newTrafficReadWriteCloser(wConn, s.stats.addIncomingTraffic, s.stats.addOutgoingTraffic)
141 141
 
142 142
 	obfs2, frame := obfuscated2.MakeTelegramObfuscated2Frame()

+ 0
- 40
proxy/timeoutrwc.go Просмотреть файл

@@ -1,40 +0,0 @@
1
-package proxy
2
-
3
-import (
4
-	"io"
5
-	"net"
6
-	"time"
7
-)
8
-
9
-// TimeoutReadWriteCloser sets timeouts for read/write into underlying
10
-// network connection.
11
-type TimeoutReadWriteCloser struct {
12
-	conn         net.Conn
13
-	readTimeout  time.Duration
14
-	writeTimeout time.Duration
15
-}
16
-
17
-// Read reads from connection
18
-func (t *TimeoutReadWriteCloser) Read(p []byte) (int, error) {
19
-	t.conn.SetReadDeadline(time.Now().Add(t.readTimeout)) // nolint: errcheck, gas
20
-	return t.conn.Read(p)
21
-}
22
-
23
-// Write writes into connection.
24
-func (t *TimeoutReadWriteCloser) Write(p []byte) (int, error) {
25
-	t.conn.SetWriteDeadline(time.Now().Add(t.writeTimeout)) // nolint: errcheck, gas
26
-	return t.conn.Write(p)
27
-}
28
-
29
-// Close closes underlying connection.
30
-func (t *TimeoutReadWriteCloser) Close() error {
31
-	return t.conn.Close()
32
-}
33
-
34
-func newTimeoutReadWriteCloser(conn net.Conn, readTimeout, writeTimeout time.Duration) io.ReadWriteCloser {
35
-	return &TimeoutReadWriteCloser{
36
-		conn:         conn,
37
-		readTimeout:  readTimeout,
38
-		writeTimeout: writeTimeout,
39
-	}
40
-}

Загрузка…
Отмена
Сохранить