本文整理匯總了Golang中github.com/v2ray/v2ray-core/common/net.TimeOutReader類的典型用法代碼示例。如果您正苦於以下問題:Golang TimeOutReader類的具體用法?Golang TimeOutReader怎麽用?Golang TimeOutReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了TimeOutReader類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleUDP
func (server *SocksServer) handleUDP(reader *v2net.TimeOutReader, writer io.Writer) error {
response := protocol.NewSocks5Response()
response.Error = protocol.ErrorSuccess
udpAddr := server.getUDPAddr()
response.Port = udpAddr.Port()
switch {
case udpAddr.IsIPv4():
response.AddrType = protocol.AddrTypeIPv4
copy(response.IPv4[:], udpAddr.IP())
case udpAddr.IsIPv6():
response.AddrType = protocol.AddrTypeIPv6
copy(response.IPv6[:], udpAddr.IP())
case udpAddr.IsDomain():
response.AddrType = protocol.AddrTypeDomain
response.Domain = udpAddr.Domain()
}
err := protocol.WriteResponse(writer, response)
if err != nil {
log.Error("Socks failed to write response: %v", err)
return err
}
reader.SetTimeOut(300) /* 5 minutes */
buffer := make([]byte, 1024)
reader.Read(buffer)
return nil
}
示例2: handleUDP
func (server *SocksServer) handleUDP(reader *v2net.TimeOutReader, writer io.Writer) error {
response := protocol.NewSocks5Response()
response.Error = protocol.ErrorSuccess
udpAddr := server.getUDPAddr()
response.Port = udpAddr.Port()
switch {
case udpAddr.IsIPv4():
response.SetIPv4(udpAddr.IP())
case udpAddr.IsIPv6():
response.SetIPv6(udpAddr.IP())
case udpAddr.IsDomain():
response.SetDomain(udpAddr.Domain())
}
responseBuffer := alloc.NewSmallBuffer().Clear()
response.Write(responseBuffer)
_, err := writer.Write(responseBuffer.Value)
responseBuffer.Release()
if err != nil {
log.Error("Socks failed to write response: %v", err)
return err
}
reader.SetTimeOut(300) /* 5 minutes */
v2net.ReadFrom(reader, nil) // Just in case of anything left in the socket
// The TCP connection closes after this method returns. We need to wait until
// the client closes it.
// TODO: get notified from UDP part
<-time.After(5 * time.Minute)
return nil
}
示例3: handleUDP
func (server *SocksServer) handleUDP(reader *v2net.TimeOutReader, writer io.Writer) error {
response := protocol.NewSocks5Response()
response.Error = protocol.ErrorSuccess
udpAddr := server.getUDPAddr()
response.Port = udpAddr.Port()
switch {
case udpAddr.IsIPv4():
response.AddrType = protocol.AddrTypeIPv4
copy(response.IPv4[:], udpAddr.IP())
case udpAddr.IsIPv6():
response.AddrType = protocol.AddrTypeIPv6
copy(response.IPv6[:], udpAddr.IP())
case udpAddr.IsDomain():
response.AddrType = protocol.AddrTypeDomain
response.Domain = udpAddr.Domain()
}
err := protocol.WriteResponse(writer, response)
if err != nil {
log.Error("Socks failed to write response: %v", err)
return err
}
reader.SetTimeOut(300) /* 5 minutes */
v2net.ReadFrom(reader, 1) // Just in case of anything left in the socket
// The TCP connection closes after this method returns. We need to wait until
// the client closes it.
// TODO: get notified from UDP part
<-time.After(5 * time.Minute)
return nil
}