mirror of https://github.com/v2ray/v2ray-core
Simplify code
parent
3aca3492eb
commit
71df5103cd
|
@ -4,7 +4,6 @@ import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -40,7 +39,11 @@ func NewVMessInboundHandler(vp *core.Point, clients user.UserSet, udpEnabled boo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *VMessInboundHandler) Listen(port uint16) error {
|
func (handler *VMessInboundHandler) Listen(port uint16) error {
|
||||||
listener, err := net.Listen("tcp", ":"+strconv.Itoa(int(port)))
|
listener, err := net.ListenTCP("tcp", &net.TCPAddr{
|
||||||
|
IP: []byte{0, 0, 0, 0},
|
||||||
|
Port: int(port),
|
||||||
|
Zone: "",
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return log.Error("Unable to listen tcp:%d", port)
|
return log.Error("Unable to listen tcp:%d", port)
|
||||||
}
|
}
|
||||||
|
@ -54,9 +57,9 @@ func (handler *VMessInboundHandler) Listen(port uint16) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *VMessInboundHandler) AcceptConnections(listener net.Listener) error {
|
func (handler *VMessInboundHandler) AcceptConnections(listener *net.TCPListener) error {
|
||||||
for handler.accepting {
|
for handler.accepting {
|
||||||
connection, err := listener.Accept()
|
connection, err := listener.AcceptTCP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return log.Error("Failed to accpet connection: %s", err.Error())
|
return log.Error("Failed to accpet connection: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -65,7 +68,7 @@ func (handler *VMessInboundHandler) AcceptConnections(listener net.Listener) err
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error {
|
func (handler *VMessInboundHandler) HandleConnection(connection *net.TCPConn) error {
|
||||||
defer connection.Close()
|
defer connection.Close()
|
||||||
|
|
||||||
connReader := v2net.NewTimeOutReader(120, connection)
|
connReader := v2net.NewTimeOutReader(120, connection)
|
||||||
|
@ -101,14 +104,14 @@ func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error
|
||||||
|
|
||||||
if data, open := <-output; open {
|
if data, open := <-output; open {
|
||||||
buffer = append(buffer, data...)
|
buffer = append(buffer, data...)
|
||||||
|
data = nil
|
||||||
responseWriter.Write(buffer)
|
responseWriter.Write(buffer)
|
||||||
|
buffer = nil
|
||||||
go handleOutput(request, responseWriter, output, &writeFinish)
|
go handleOutput(request, responseWriter, output, &writeFinish)
|
||||||
writeFinish.Lock()
|
writeFinish.Lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
if tcpConn, ok := connection.(*net.TCPConn); ok {
|
connection.CloseWrite()
|
||||||
tcpConn.CloseWrite()
|
|
||||||
}
|
|
||||||
readFinish.Lock()
|
readFinish.Lock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue