1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-04 09:17:32 -05:00

Don't send any request when client or target server closes connection.

This commit is contained in:
V2Ray 2015-09-18 12:31:26 +02:00
parent c504144792
commit 790db40821
2 changed files with 18 additions and 27 deletions

View File

@ -77,24 +77,18 @@ func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error
if err != nil { if err != nil {
return log.Error("Failed to create encrypt writer: %v", err) return log.Error("Failed to create encrypt writer: %v", err)
} }
//responseWriter.Write(response[:])
// Optimize for small response packet // Optimize for small response packet
buffer := make([]byte, 0, 1024) buffer := make([]byte, 0, 1024)
buffer = append(buffer, response[:]...) buffer = append(buffer, response[:]...)
data, open := <-output
if open { if data, open := <-output; open {
buffer = append(buffer, data...) buffer = append(buffer, data...)
}
responseWriter.Write(buffer) responseWriter.Write(buffer)
if open {
go handleOutput(request, responseWriter, output, writeFinish) go handleOutput(request, responseWriter, output, writeFinish)
} else { <-writeFinish
close(writeFinish)
} }
<-writeFinish
if tcpConn, ok := connection.(*net.TCPConn); ok { if tcpConn, ok := connection.(*net.TCPConn); ok {
log.Debug("VMessIn closing write") log.Debug("VMessIn closing write")
tcpConn.CloseWrite() tcpConn.CloseWrite()

View File

@ -108,23 +108,20 @@ func handleRequest(conn *net.TCPConn, request *vmessio.VMessRequest, input <-cha
if err != nil { if err != nil {
log.Error("VMessOut: Failed to serialize VMess request: %v", err) log.Error("VMessOut: Failed to serialize VMess request: %v", err)
} }
//conn.Write(buffer)
data, open := <-input // Send first packet of payload together with request, in favor of small requests.
payload, open := <-input
if open { if open {
encryptRequestWriter.Crypt(data) encryptRequestWriter.Crypt(payload)
buffer = append(buffer, data...) buffer = append(buffer, payload...)
}
_, err = conn.Write(buffer) _, err = conn.Write(buffer)
if err != nil { if err != nil {
log.Error("VMessOut: Failed to write VMess request: %v", err) log.Error("VMessOut: Failed to write VMess request: %v", err)
} }
if !open {
return nil
}
v2net.ChanToWriter(encryptRequestWriter, input) v2net.ChanToWriter(encryptRequestWriter, input)
}
return nil return nil
} }