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

pull/27/head
V2Ray 9 years ago
parent c504144792
commit 790db40821

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

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

Loading…
Cancel
Save