1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-04 16:37:12 -05:00

remove release() pattern

This commit is contained in:
Darien Raymond 2017-01-04 12:52:24 +01:00
parent 49210d8362
commit e678000c44
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
33 changed files with 17 additions and 232 deletions

View File

@ -44,11 +44,6 @@ func (v *DefaultDispatcher) Initialize(space app.Space) error {
return nil return nil
} }
// Release implements common.Releasable.Release().
func (v *DefaultDispatcher) Release() {
}
func (v *DefaultDispatcher) DispatchToOutbound(session *proxy.SessionInfo) ray.InboundRay { func (v *DefaultDispatcher) DispatchToOutbound(session *proxy.SessionInfo) ray.InboundRay {
dispatcher := v.ohm.GetDefaultHandler() dispatcher := v.ohm.GetDefaultHandler()
destination := session.Destination destination := session.Destination

View File

@ -66,10 +66,6 @@ func NewCacheServer(space app.Space, config *dns.Config) *CacheServer {
return server return server
} }
func (v *CacheServer) Release() {
}
// Private: Visible for testing. // Private: Visible for testing.
func (v *CacheServer) GetCached(domain string) []net.IP { func (v *CacheServer) GetCached(domain string) []net.IP {
v.RLock() v.RLock()

View File

@ -54,11 +54,6 @@ func (v *OutboundProxy) Dial(src v2net.Address, dest v2net.Destination, options
return NewConnection(src, dest, stream), nil return NewConnection(src, dest, stream), nil
} }
// Release implements common.Releasable.Release().
func (v *OutboundProxy) Release() {
}
type Connection struct { type Connection struct {
stream ray.Ray stream ray.Ray
closed bool closed bool
@ -105,9 +100,7 @@ func (v *Connection) Write(b []byte) (int, error) {
func (v *Connection) Close() error { func (v *Connection) Close() error {
v.closed = true v.closed = true
v.stream.InboundInput().Close() v.stream.InboundInput().Close()
v.stream.InboundOutput().Release() v.stream.InboundOutput().ForceClose()
v.reader.Release()
v.writer.Release()
return nil return nil
} }

View File

@ -2,6 +2,7 @@ package outbound
import ( import (
"sync" "sync"
"v2ray.com/core/app" "v2ray.com/core/app"
"v2ray.com/core/app/proxyman" "v2ray.com/core/app/proxyman"
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"
@ -20,10 +21,6 @@ func New() *DefaultOutboundHandlerManager {
} }
} }
func (v *DefaultOutboundHandlerManager) Release() {
}
func (v *DefaultOutboundHandlerManager) GetDefaultHandler() proxy.OutboundHandler { func (v *DefaultOutboundHandlerManager) GetDefaultHandler() proxy.OutboundHandler {
v.RLock() v.RLock()
defer v.RUnlock() defer v.RUnlock()

View File

@ -52,10 +52,6 @@ func NewRouter(config *Config, space app.Space) *Router {
return r return r
} }
func (v *Router) Release() {
}
// Private: Visible for testing. // Private: Visible for testing.
func (v *Router) ResolveIP(dest v2net.Destination) []v2net.Destination { func (v *Router) ResolveIP(dest v2net.Destination) []v2net.Destination {
ips := v.dnsServer.Get(dest.Address.Domain()) ips := v.dnsServer.Get(dest.Address.Domain())

View File

@ -1,9 +1,6 @@
package app package app
import ( import "v2ray.com/core/common/errors"
"v2ray.com/core/common"
"v2ray.com/core/common/errors"
)
type ID int type ID int
@ -17,7 +14,6 @@ type Caller interface {
} }
type Application interface { type Application interface {
common.Releasable
} }
type ApplicationInitializer func() error type ApplicationInitializer func() error

View File

@ -1,15 +1,11 @@
package web package web
import ( import "v2ray.com/core/app"
"v2ray.com/core/app"
"v2ray.com/core/common"
)
const ( const (
APP_ID = app.ID(8) APP_ID = app.ID(8)
) )
type WebServer interface { type WebServer interface {
common.Releasable
Handle() Handle()
} }

View File

@ -8,14 +8,12 @@ import (
// Reader extends io.Reader with alloc.Buffer. // Reader extends io.Reader with alloc.Buffer.
type Reader interface { type Reader interface {
Release()
// Read reads content from underlying reader, and put it into an alloc.Buffer. // Read reads content from underlying reader, and put it into an alloc.Buffer.
Read() (*Buffer, error) Read() (*Buffer, error)
} }
// Writer extends io.Writer with alloc.Buffer. // Writer extends io.Writer with alloc.Buffer.
type Writer interface { type Writer interface {
Release()
// Write writes an alloc.Buffer into underlying writer. // Write writes an alloc.Buffer into underlying writer.
Write(*Buffer) error Write(*Buffer) error
} }

View File

@ -1,7 +1,6 @@
package buf package buf
import "io" import "io"
import "v2ray.com/core/common"
// BytesToBufferReader is a Reader that adjusts its reading speed automatically. // BytesToBufferReader is a Reader that adjusts its reading speed automatically.
type BytesToBufferReader struct { type BytesToBufferReader struct {
@ -44,11 +43,6 @@ func (v *BytesToBufferReader) Read() (*Buffer, error) {
return buffer, nil return buffer, nil
} }
// Release implements Releasable.Release().
func (v *BytesToBufferReader) Release() {
common.Release(v.reader)
}
type BufferToBytesReader struct { type BufferToBytesReader struct {
stream Reader stream Reader
current *Buffer current *Buffer
@ -84,10 +78,3 @@ func (v *BufferToBytesReader) Read(b []byte) (int, error) {
} }
return nBytes, err return nBytes, err
} }
// Release implements Releasable.Release().
func (v *BufferToBytesReader) Release() {
v.eof = true
v.current.Release()
v.current = nil
}

View File

@ -1,7 +1,6 @@
package buf package buf
import "io" import "io"
import "v2ray.com/core/common"
// BufferToBytesWriter is a Writer that writes alloc.Buffer into underlying writer. // BufferToBytesWriter is a Writer that writes alloc.Buffer into underlying writer.
type BufferToBytesWriter struct { type BufferToBytesWriter struct {
@ -24,11 +23,6 @@ func (v *BufferToBytesWriter) Write(buffer *Buffer) error {
return nil return nil
} }
// Release implements Releasable.Release().
func (v *BufferToBytesWriter) Release() {
common.Release(v.writer)
}
type BytesToBufferWriter struct { type BytesToBufferWriter struct {
writer Writer writer Writer
} }
@ -50,8 +44,3 @@ func (v *BytesToBufferWriter) Write(payload []byte) (int, error) {
return bytesWritten, nil return bytesWritten, nil
} }
// Release implements Releasable.Release()
func (v *BytesToBufferWriter) Release() {
v.writer.Release()
}

View File

@ -3,7 +3,6 @@ package bufio
import ( import (
"io" "io"
"v2ray.com/core/common"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
) )
@ -18,21 +17,11 @@ type BufferedReader struct {
func NewReader(rawReader io.Reader) *BufferedReader { func NewReader(rawReader io.Reader) *BufferedReader {
return &BufferedReader{ return &BufferedReader{
reader: rawReader, reader: rawReader,
buffer: buf.New(), buffer: buf.NewLocal(1024),
buffered: true, buffered: true,
} }
} }
// Release implements Releasable.Release().
func (v *BufferedReader) Release() {
if v.buffer != nil {
v.buffer.Release()
v.buffer = nil
}
common.Release(v.reader)
}
// IsBuffered returns true if the internal cache is effective. // IsBuffered returns true if the internal cache is effective.
func (v *BufferedReader) IsBuffered() bool { func (v *BufferedReader) IsBuffered() bool {
return v.buffered return v.buffered

View File

@ -3,7 +3,6 @@ package bufio
import ( import (
"io" "io"
"v2ray.com/core/common"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
"v2ray.com/core/common/errors" "v2ray.com/core/common/errors"
) )
@ -20,7 +19,7 @@ type BufferedWriter struct {
func NewWriter(rawWriter io.Writer) *BufferedWriter { func NewWriter(rawWriter io.Writer) *BufferedWriter {
return &BufferedWriter{ return &BufferedWriter{
writer: rawWriter, writer: rawWriter,
buffer: buf.NewSmall(), buffer: buf.NewLocal(1024),
buffered: true, buffered: true,
} }
} }
@ -91,16 +90,3 @@ func (v *BufferedWriter) SetBuffered(cached bool) {
v.Flush() v.Flush()
} }
} }
// Release implements common.Releasable.Release().
func (v *BufferedWriter) Release() {
if !v.buffer.IsEmpty() {
v.Flush()
}
if v.buffer != nil {
v.buffer.Release()
v.buffer = nil
}
common.Release(v.writer)
}

View File

@ -40,14 +40,14 @@ func TestBufferedWriterLargePayload(t *testing.T) {
payload := make([]byte, 64*1024) payload := make([]byte, 64*1024)
rand.Read(payload) rand.Read(payload)
nBytes, err := writer.Write(payload[:1024]) nBytes, err := writer.Write(payload[:512])
assert.Int(nBytes).Equals(1024) assert.Int(nBytes).Equals(512)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.Bool(content.IsEmpty()).IsTrue() assert.Bool(content.IsEmpty()).IsTrue()
nBytes, err = writer.Write(payload[1024:]) nBytes, err = writer.Write(payload[512:])
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.Int(nBytes).Equals(63 * 1024) assert.Int(nBytes).Equals(64*1024 - 512)
assert.Bytes(content.Bytes()).Equals(payload) assert.Bytes(content.Bytes()).Equals(payload)
} }

View File

@ -13,19 +13,6 @@ var (
ErrDuplicatedName = errors.New("Duplicated name.") ErrDuplicatedName = errors.New("Duplicated name.")
) )
// Releasable interface is for those types that can release its members.
type Releasable interface {
// Release releases all references to accelerate garbage collection.
Release()
}
// Release tries to release the given object.
func Release(v interface{}) {
if releasable, ok := v.(Releasable); ok {
releasable.Release()
}
}
// Must panics if err is not nil. // Must panics if err is not nil.
func Must(err error) { func Must(err error) {
if err != nil { if err != nil {

View File

@ -3,8 +3,6 @@ package crypto
import ( import (
"crypto/cipher" "crypto/cipher"
"io" "io"
"v2ray.com/core/common"
) )
type CryptionReader struct { type CryptionReader struct {
@ -27,11 +25,6 @@ func (v *CryptionReader) Read(data []byte) (int, error) {
return nBytes, err return nBytes, err
} }
func (v *CryptionReader) Release() {
common.Release(v.reader)
common.Release(v.stream)
}
type CryptionWriter struct { type CryptionWriter struct {
stream cipher.Stream stream cipher.Stream
writer io.Writer writer io.Writer
@ -50,9 +43,3 @@ func (v *CryptionWriter) Write(data []byte) (int, error) {
v.stream.XORKeyStream(data, data) v.stream.XORKeyStream(data, data)
return v.writer.Write(data) return v.writer.Write(data)
} }
// Release implements common.Releasable.Release().
func (v *CryptionWriter) Release() {
common.Release(v.writer)
common.Release(v.stream)
}

View File

@ -4,12 +4,10 @@ import (
"fmt" "fmt"
"strings" "strings"
"v2ray.com/core/common"
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"
) )
type LogEntry interface { type LogEntry interface {
common.Releasable
fmt.Stringer fmt.Stringer
} }
@ -18,12 +16,6 @@ type ErrorLog struct {
Values []interface{} Values []interface{}
} }
func (v *ErrorLog) Release() {
for _, val := range v.Values {
common.Release(val)
}
}
func (v *ErrorLog) String() string { func (v *ErrorLog) String() string {
return v.Prefix + serial.Concat(v.Values...) return v.Prefix + serial.Concat(v.Values...)
} }
@ -35,12 +27,6 @@ type AccessLog struct {
Reason interface{} Reason interface{}
} }
func (v *AccessLog) Release() {
common.Release(v.From)
common.Release(v.To)
common.Release(v.Reason)
}
func (v *AccessLog) String() string { func (v *AccessLog) String() string {
return strings.Join([]string{serial.ToString(v.From), v.Status, serial.ToString(v.To), serial.ToString(v.Reason)}, " ") return strings.Join([]string{serial.ToString(v.From), v.Status, serial.ToString(v.To), serial.ToString(v.Reason)}, " ")
} }

View File

@ -17,9 +17,7 @@ type LogWriter interface {
type NoOpLogWriter struct { type NoOpLogWriter struct {
} }
func (v *NoOpLogWriter) Log(entry LogEntry) { func (v *NoOpLogWriter) Log(entry LogEntry) {}
entry.Release()
}
func (v *NoOpLogWriter) Close() { func (v *NoOpLogWriter) Close() {
} }
@ -38,7 +36,6 @@ func NewStdOutLogWriter() LogWriter {
func (v *StdOutLogWriter) Log(log LogEntry) { func (v *StdOutLogWriter) Log(log LogEntry) {
v.logger.Print(log.String() + platform.LineSeparator()) v.logger.Print(log.String() + platform.LineSeparator())
log.Release()
} }
func (v *StdOutLogWriter) Close() { func (v *StdOutLogWriter) Close() {
@ -58,7 +55,6 @@ func (v *FileLogWriter) Log(log LogEntry) {
default: default:
// We don't expect this to happen, but don't want to block main thread as well. // We don't expect this to happen, but don't want to block main thread as well.
} }
log.Release()
} }
func (v *FileLogWriter) run() { func (v *FileLogWriter) run() {

View File

@ -4,8 +4,6 @@ import (
"io" "io"
"net" "net"
"time" "time"
"v2ray.com/core/common"
) )
var ( var (
@ -52,11 +50,6 @@ func (reader *TimeOutReader) SetTimeOut(value uint32) {
} }
} }
func (reader *TimeOutReader) Release() {
common.Release(reader.connection)
common.Release(reader.worker)
}
type timedReaderWorker struct { type timedReaderWorker struct {
timeout uint32 timeout uint32
connection net.Conn connection net.Conn

View File

@ -1,12 +1,7 @@
package protocol package protocol
import (
"v2ray.com/core/common"
)
type UserValidator interface { type UserValidator interface {
common.Releasable
Add(user *User) error Add(user *User) error
Get(timeHash []byte) (*User, Timestamp, bool) Get(timeHash []byte) (*User, Timestamp, bool)
Release()
} }

View File

@ -31,7 +31,7 @@ func (v *Handler) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
v.response.WriteTo(ray.OutboundOutput()) v.response.WriteTo(ray.OutboundOutput())
ray.OutboundOutput().Close() ray.OutboundOutput().Close()
ray.OutboundInput().Release() ray.OutboundInput().ForceClose()
} }
// Factory is an utility for creating blackhole handlers. // Factory is an utility for creating blackhole handlers.

View File

@ -172,13 +172,11 @@ func (v *DokodemoDoor) HandleTCPConnection(conn internet.Connection) {
defer output.ForceClose() defer output.ForceClose()
reader := v2net.NewTimeOutReader(v.config.Timeout, conn) reader := v2net.NewTimeOutReader(v.config.Timeout, conn)
defer reader.Release()
requestDone := signal.ExecuteAsync(func() error { requestDone := signal.ExecuteAsync(func() error {
defer ray.InboundInput().Close() defer ray.InboundInput().Close()
v2reader := buf.NewReader(reader) v2reader := buf.NewReader(reader)
defer v2reader.Release()
if err := buf.PipeUntilEOF(v2reader, ray.InboundInput()); err != nil { if err := buf.PipeUntilEOF(v2reader, ray.InboundInput()); err != nil {
log.Info("Dokodemo: Failed to transport all TCP request: ", err) log.Info("Dokodemo: Failed to transport all TCP request: ", err)
@ -192,7 +190,6 @@ func (v *DokodemoDoor) HandleTCPConnection(conn internet.Connection) {
defer output.ForceClose() defer output.ForceClose()
v2writer := buf.NewWriter(conn) v2writer := buf.NewWriter(conn)
defer v2writer.Release()
if err := buf.PipeUntilEOF(output, v2writer); err != nil { if err := buf.PipeUntilEOF(output, v2writer); err != nil {
log.Info("Dokodemo: Failed to transport all TCP response: ", err) log.Info("Dokodemo: Failed to transport all TCP response: ", err)

View File

@ -99,8 +99,6 @@ func (v *Handler) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
defer input.ForceClose() defer input.ForceClose()
v2writer := buf.NewWriter(conn) v2writer := buf.NewWriter(conn)
defer v2writer.Release()
if err := buf.PipeUntilEOF(input, v2writer); err != nil { if err := buf.PipeUntilEOF(input, v2writer); err != nil {
return err return err
} }
@ -121,8 +119,6 @@ func (v *Handler) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
defer output.Close() defer output.Close()
v2reader := buf.NewReader(reader) v2reader := buf.NewReader(reader)
defer v2reader.Release()
if err := buf.PipeUntilEOF(v2reader, output); err != nil { if err := buf.PipeUntilEOF(v2reader, output); err != nil {
return err return err
} }

View File

@ -162,8 +162,6 @@ func (v *Server) handleConnect(request *http.Request, session *proxy.SessionInfo
defer ray.InboundInput().Close() defer ray.InboundInput().Close()
v2reader := buf.NewReader(reader) v2reader := buf.NewReader(reader)
defer v2reader.Release()
if err := buf.PipeUntilEOF(v2reader, ray.InboundInput()); err != nil { if err := buf.PipeUntilEOF(v2reader, ray.InboundInput()); err != nil {
return err return err
} }
@ -174,8 +172,6 @@ func (v *Server) handleConnect(request *http.Request, session *proxy.SessionInfo
defer ray.InboundOutput().ForceClose() defer ray.InboundOutput().ForceClose()
v2writer := buf.NewWriter(writer) v2writer := buf.NewWriter(writer)
defer v2writer.Release()
if err := buf.PipeUntilEOF(ray.InboundOutput(), v2writer); err != nil { if err := buf.PipeUntilEOF(ray.InboundOutput(), v2writer); err != nil {
return err return err
} }
@ -248,8 +244,6 @@ func (v *Server) handlePlainHTTP(request *http.Request, session *proxy.SessionIn
defer input.Close() defer input.Close()
requestWriter := bufio.NewWriter(buf.NewBytesWriter(ray.InboundInput())) requestWriter := bufio.NewWriter(buf.NewBytesWriter(ray.InboundInput()))
defer requestWriter.Release()
err := request.Write(requestWriter) err := request.Write(requestWriter)
if err != nil { if err != nil {
return err return err

View File

@ -87,11 +87,7 @@ func (v *Client) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
if request.Command == protocol.RequestCommandTCP { if request.Command == protocol.RequestCommandTCP {
bufferedWriter := bufio.NewWriter(conn) bufferedWriter := bufio.NewWriter(conn)
defer bufferedWriter.Release()
bodyWriter, err := WriteTCPRequest(request, bufferedWriter) bodyWriter, err := WriteTCPRequest(request, bufferedWriter)
defer bodyWriter.Release()
if err != nil { if err != nil {
log.Info("Shadowsocks|Client: Failed to write request: ", err) log.Info("Shadowsocks|Client: Failed to write request: ", err)
return return

View File

@ -6,7 +6,6 @@ import (
"crypto/sha1" "crypto/sha1"
"io" "io"
"v2ray.com/core/common"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
"v2ray.com/core/common/errors" "v2ray.com/core/common/errors"
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"
@ -70,11 +69,6 @@ func NewChunkReader(reader io.Reader, auth *Authenticator) *ChunkReader {
} }
} }
func (v *ChunkReader) Release() {
common.Release(v.reader)
common.Release(v.auth)
}
func (v *ChunkReader) Read() (*buf.Buffer, error) { func (v *ChunkReader) Read() (*buf.Buffer, error) {
buffer := buf.New() buffer := buf.New()
if err := buffer.AppendSupplier(buf.ReadFullFrom(v.reader, 2)); err != nil { if err := buffer.AppendSupplier(buf.ReadFullFrom(v.reader, 2)); err != nil {
@ -124,11 +118,6 @@ func NewChunkWriter(writer io.Writer, auth *Authenticator) *ChunkWriter {
} }
} }
func (v *ChunkWriter) Release() {
common.Release(v.writer)
common.Release(v.auth)
}
func (v *ChunkWriter) Write(payload *buf.Buffer) error { func (v *ChunkWriter) Write(payload *buf.Buffer) error {
totalLength := payload.Len() totalLength := payload.Len()
serial.Uint16ToBytes(uint16(totalLength), v.buffer[:0]) serial.Uint16ToBytes(uint16(totalLength), v.buffer[:0])

View File

@ -378,9 +378,6 @@ func (v *UDPReader) Read() (*buf.Buffer, error) {
return payload, nil return payload, nil
} }
func (v *UDPReader) Release() {
}
type UDPWriter struct { type UDPWriter struct {
Writer io.Writer Writer io.Writer
Request *protocol.RequestHeader Request *protocol.RequestHeader
@ -395,7 +392,3 @@ func (v *UDPWriter) Write(buffer *buf.Buffer) error {
payload.Release() payload.Release()
return err return err
} }
func (v *UDPWriter) Release() {
}

View File

@ -147,18 +147,13 @@ func (v *Server) handleConnection(conn internet.Connection) {
conn.SetReusable(false) conn.SetReusable(false)
timedReader := v2net.NewTimeOutReader(16, conn) timedReader := v2net.NewTimeOutReader(16, conn)
defer timedReader.Release()
bufferedReader := bufio.NewReader(timedReader) bufferedReader := bufio.NewReader(timedReader)
defer bufferedReader.Release()
request, bodyReader, err := ReadTCPSession(v.user, bufferedReader) request, bodyReader, err := ReadTCPSession(v.user, bufferedReader)
if err != nil { if err != nil {
log.Access(conn.RemoteAddr(), "", log.AccessRejected, err) log.Access(conn.RemoteAddr(), "", log.AccessRejected, err)
log.Info("Shadowsocks|Server: Failed to create request from: ", conn.RemoteAddr(), ": ", err) log.Info("Shadowsocks|Server: Failed to create request from: ", conn.RemoteAddr(), ": ", err)
return return
} }
defer bodyReader.Release()
bufferedReader.SetBuffered(false) bufferedReader.SetBuffered(false)
@ -182,14 +177,11 @@ func (v *Server) handleConnection(conn internet.Connection) {
defer ray.InboundOutput().ForceClose() defer ray.InboundOutput().ForceClose()
bufferedWriter := bufio.NewWriter(conn) bufferedWriter := bufio.NewWriter(conn)
defer bufferedWriter.Release()
responseWriter, err := WriteTCPResponse(request, bufferedWriter) responseWriter, err := WriteTCPResponse(request, bufferedWriter)
if err != nil { if err != nil {
log.Warning("Shadowsocks|Server: Failed to write response: ", err) log.Warning("Shadowsocks|Server: Failed to write response: ", err)
return err return err
} }
defer responseWriter.Release()
payload, err := ray.InboundOutput().Read() payload, err := ray.InboundOutput().Read()
if err != nil { if err != nil {

View File

@ -105,7 +105,6 @@ func (v *Server) handleConnection(connection internet.Connection) {
timedReader := v2net.NewTimeOutReader(v.config.Timeout, connection) timedReader := v2net.NewTimeOutReader(v.config.Timeout, connection)
reader := bufio.NewReader(timedReader) reader := bufio.NewReader(timedReader)
defer reader.Release()
session := &ServerSession{ session := &ServerSession{
config: v.config, config: v.config,
@ -159,8 +158,6 @@ func (v *Server) transport(reader io.Reader, writer io.Writer, session *proxy.Se
defer input.Close() defer input.Close()
v2reader := buf.NewReader(reader) v2reader := buf.NewReader(reader)
defer v2reader.Release()
if err := buf.PipeUntilEOF(v2reader, input); err != nil { if err := buf.PipeUntilEOF(v2reader, input); err != nil {
log.Info("Socks|Server: Failed to transport all TCP request: ", err) log.Info("Socks|Server: Failed to transport all TCP request: ", err)
return err return err
@ -172,8 +169,6 @@ func (v *Server) transport(reader io.Reader, writer io.Writer, session *proxy.Se
defer output.ForceClose() defer output.ForceClose()
v2writer := buf.NewWriter(writer) v2writer := buf.NewWriter(writer)
defer v2writer.Release()
if err := buf.PipeUntilEOF(output, v2writer); err != nil { if err := buf.PipeUntilEOF(output, v2writer); err != nil {
log.Info("Socks|Server: Failed to transport all TCP response: ", err) log.Info("Socks|Server: Failed to transport all TCP response: ", err)
return err return err

View File

@ -37,16 +37,6 @@ func NewServerSession(validator protocol.UserValidator) *ServerSession {
} }
} }
// Release implements common.Releaseable.
func (v *ServerSession) Release() {
v.userValidator = nil
v.requestBodyIV = nil
v.requestBodyKey = nil
v.responseBodyIV = nil
v.responseBodyKey = nil
v.responseWriter = nil
}
func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.RequestHeader, error) { func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.RequestHeader, error) {
buffer := make([]byte, 512) buffer := make([]byte, 512)

View File

@ -87,15 +87,15 @@ func (v *VMessInboundHandler) Port() v2net.Port {
} }
func (v *VMessInboundHandler) Close() { func (v *VMessInboundHandler) Close() {
v.Lock()
v.accepting = false v.accepting = false
if v.listener != nil { if v.listener != nil {
v.Lock()
v.listener.Close() v.listener.Close()
v.listener = nil v.listener = nil
v.clients.Release() v.clients.Release()
v.clients = nil v.clients = nil
v.Unlock()
} }
v.Unlock()
} }
func (v *VMessInboundHandler) GetUser(email string) *protocol.User { func (v *VMessInboundHandler) GetUser(email string) *protocol.User {
@ -134,8 +134,6 @@ func transferRequest(session *encoding.ServerSession, request *protocol.RequestH
defer output.Close() defer output.Close()
bodyReader := session.DecodeRequestBody(request, input) bodyReader := session.DecodeRequestBody(request, input)
defer bodyReader.Release()
if err := buf.PipeUntilEOF(bodyReader, output); err != nil { if err := buf.PipeUntilEOF(bodyReader, output); err != nil {
return err return err
} }
@ -180,19 +178,13 @@ func (v *VMessInboundHandler) HandleConnection(connection internet.Connection) {
} }
connReader := v2net.NewTimeOutReader(8, connection) connReader := v2net.NewTimeOutReader(8, connection)
defer connReader.Release()
reader := bufio.NewReader(connReader) reader := bufio.NewReader(connReader)
defer reader.Release()
v.RLock() v.RLock()
if !v.accepting { if !v.accepting {
v.RUnlock() v.RUnlock()
return return
} }
session := encoding.NewServerSession(v.clients) session := encoding.NewServerSession(v.clients)
defer session.Release()
request, err := session.DecodeRequestHeader(reader) request, err := session.DecodeRequestHeader(reader)
v.RUnlock() v.RUnlock()
@ -229,8 +221,6 @@ func (v *VMessInboundHandler) HandleConnection(connection internet.Connection) {
}) })
writer := bufio.NewWriter(connection) writer := bufio.NewWriter(connection)
defer writer.Release()
response := &protocol.ResponseHeader{ response := &protocol.ResponseHeader{
Command: v.generateCommand(request), Command: v.generateCommand(request),
} }

View File

@ -88,13 +88,9 @@ func (v *VMessOutboundHandler) Dispatch(target v2net.Destination, outboundRay ra
defer input.ForceClose() defer input.ForceClose()
writer := bufio.NewWriter(conn) writer := bufio.NewWriter(conn)
defer writer.Release()
session.EncodeRequestHeader(request, writer) session.EncodeRequestHeader(request, writer)
bodyWriter := session.EncodeRequestBody(request, writer) bodyWriter := session.EncodeRequestBody(request, writer)
defer bodyWriter.Release()
firstPayload, err := input.ReadTimeout(time.Millisecond * 500) firstPayload, err := input.ReadTimeout(time.Millisecond * 500)
if err != nil && err != ray.ErrReadTimeout { if err != nil && err != ray.ErrReadTimeout {
return errors.Base(err).Message("VMess|Outbound: Failed to get first payload.") return errors.Base(err).Message("VMess|Outbound: Failed to get first payload.")
@ -124,8 +120,6 @@ func (v *VMessOutboundHandler) Dispatch(target v2net.Destination, outboundRay ra
defer output.Close() defer output.Close()
reader := bufio.NewReader(conn) reader := bufio.NewReader(conn)
defer reader.Release()
header, err := session.DecodeResponseHeader(reader) header, err := session.DecodeResponseHeader(reader)
if err != nil { if err != nil {
return err return err
@ -136,8 +130,6 @@ func (v *VMessOutboundHandler) Dispatch(target v2net.Destination, outboundRay ra
reader.SetBuffered(false) reader.SetBuffered(false)
bodyReader := session.DecodeResponseBody(request, reader) bodyReader := session.DecodeResponseBody(request, reader)
defer bodyReader.Release()
if err := buf.PipeUntilEOF(bodyReader, output); err != nil { if err := buf.PipeUntilEOF(bodyReader, output); err != nil {
return err return err
} }

View File

@ -1,7 +1,6 @@
package kcp package kcp
import ( import (
"v2ray.com/core/common"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"
) )
@ -27,7 +26,7 @@ const (
) )
type Segment interface { type Segment interface {
common.Releasable Release()
Conversation() uint16 Conversation() uint16
Command() Command Command() Command
ByteSize() int ByteSize() int

View File

@ -88,7 +88,7 @@ func (v *TimedInboundRay) Release() {
} }
v.server = nil v.server = nil
v.inboundRay.InboundInput().Close() v.inboundRay.InboundInput().Close()
v.inboundRay.InboundOutput().Release() v.inboundRay.InboundOutput().ForceClose()
v.inboundRay = nil v.inboundRay = nil
} }