mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-03 00:22:05 +00:00
Close connection more aggressively.
This commit is contained in:
1 parent
64103229d6
commit
a78dbe7133
5 files changed
+45
-13
No files matched your search
@@ -0,0 +1,30 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
emptyTime time.Time
|
||||
)
|
||||
|
||||
type TimeOutReader struct {
|
||||
timeout int
|
||||
connection net.Conn
|
||||
}
|
||||
|
||||
func NewTimeOutReader(timeout int, connection net.Conn) *TimeOutReader {
|
||||
return &TimeOutReader{
|
||||
timeout: timeout,
|
||||
connection: connection,
|
||||
}
|
||||
}
|
||||
|
||||
func (reader *TimeOutReader) Read(p []byte) (n int, err error) {
|
||||
deadline := time.Duration(reader.timeout) * time.Second
|
||||
reader.connection.SetReadDeadline(time.Now().Add(deadline))
|
||||
n, err = reader.connection.Read(p)
|
||||
reader.connection.SetReadDeadline(emptyTime)
|
||||
return
|
||||
}
|
||||
Reference in new issue
Block a user