1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -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 {
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()

View File

@ -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
// Send first packet of payload together with request, in favor of small requests.
payload, open := <-input
if open {
encryptRequestWriter.Crypt(data)
buffer = append(buffer, data...)
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)
}
_, err = conn.Write(buffer)
if err != nil {
log.Error("VMessOut: Failed to write VMess request: %v", err)
}
if !open {
return nil
}
v2net.ChanToWriter(encryptRequestWriter, input)
return nil
}