@@ -30,7 +30,7 @@ func TestRequestSerialization(t *testing.T) {
Version: 1,
User: user,
Command: protocol.RequestCommandTCP,
- Option: protocol.RequestOption(0),
+ Option: protocol.RequestOptionConnectionReuse,
Address: v2net.DomainAddress("www.v2ray.com"),
Port: v2net.Port(443),
Security: protocol.Security(protocol.SecurityType_AES128_GCM),
@@ -153,6 +153,8 @@ func (v *VMessInboundHandler) HandleConnection(connection internet.Connection) {
request, err := session.DecodeRequestHeader(reader)
v.RUnlock()
+ connection.SetReusable(request.Option.Has(protocol.RequestOptionConnectionReuse))
+
if err != nil {
if errors.Cause(err) != io.EOF {
log.Access(connection.RemoteAddr(), "", log.AccessRejected, err)
@@ -138,9 +138,7 @@ func (v *VMessOutboundHandler) handleResponse(session *encoding.ClientSession, c
}
go v.handleCommand(dest, header.Command)
- if !header.Option.Has(protocol.ResponseOptionConnectionReuse) {
- conn.SetReusable(false)
- }
+ conn.SetReusable(header.Option.Has(protocol.ResponseOptionConnectionReuse))
reader.SetCached(false)
bodyReader := session.DecodeResponseBody(request, reader)
@@ -93,14 +93,11 @@ func (v *Connection) SetWriteDeadline(t time.Time) error {
func (v *Connection) SetReusable(reusable bool) {
- if !v.config.ConnectionReuse.IsEnabled() {
- return
v.reusable = reusable
func (v *Connection) Reusable() bool {
- return v.reusable
+ return v.config.ConnectionReuse.IsEnabled() && v.reusable
func (v *Connection) SysFd() (int, error) {