當前位置: 首頁>>代碼示例>>Golang>>正文


Golang retry.Timed函數代碼示例

本文整理匯總了Golang中github.com/v2ray/v2ray-core/common/retry.Timed函數的典型用法代碼示例。如果您正苦於以下問題:Golang Timed函數的具體用法?Golang Timed怎麽用?Golang Timed使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Timed函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Dispatch

func (this *FreedomConnection) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error {
	log.Info("Freedom: Opening connection to ", firstPacket.Destination())

	var conn net.Conn
	err := retry.Timed(5, 100).On(func() error {
		rawConn, err := dialer.Dial(firstPacket.Destination())
		if err != nil {
			return err
		}
		conn = rawConn
		return nil
	})
	if err != nil {
		close(ray.OutboundOutput())
		log.Error("Freedom: Failed to open connection to ", firstPacket.Destination(), ": ", err)
		return err
	}
	defer conn.Close()

	input := ray.OutboundInput()
	output := ray.OutboundOutput()
	var readMutex, writeMutex sync.Mutex
	readMutex.Lock()
	writeMutex.Lock()

	if chunk := firstPacket.Chunk(); chunk != nil {
		conn.Write(chunk.Value)
		chunk.Release()
	}

	if !firstPacket.MoreChunks() {
		writeMutex.Unlock()
	} else {
		go func() {
			v2io.ChanToRawWriter(conn, input)
			writeMutex.Unlock()
		}()
	}

	go func() {
		defer readMutex.Unlock()
		defer close(output)

		var reader io.Reader = conn

		if firstPacket.Destination().IsUDP() {
			reader = v2net.NewTimeOutReader(16 /* seconds */, conn)
		}

		v2io.RawReaderToChan(output, reader)
	}()

	writeMutex.Lock()
	if tcpConn, ok := conn.(*net.TCPConn); ok {
		tcpConn.CloseWrite()
	}
	readMutex.Lock()

	return nil
}
開發者ID:orvice,項目名稱:v2ray-core,代碼行數:60,代碼來源:freedom.go

示例2: refresh

func (this *InboundDetourHandlerDynamic) refresh() error {
	this.lastRefresh = time.Now()

	for _, ich := range this.ich2Recycle {
		port2Delete := ich.Port()

		ich.Close()
		err := retry.Timed(100 /* times */, 1000 /* ms */).On(func() error {
			port := this.pickUnusedPort()
			err := ich.Listen(port)
			if err != nil {
				log.Error("Point: Failed to start inbound detour on port ", port, ": ", err)
				return err
			}
			this.portsInUse[port] = true
			return nil
		})
		if err != nil {
			continue
		}

		delete(this.portsInUse, port2Delete)
	}

	this.Lock()
	this.ich2Recycle, this.ichInUse = this.ichInUse, this.ich2Recycle
	this.Unlock()

	return nil
}
開發者ID:wangyou,項目名稱:v2ray-core,代碼行數:30,代碼來源:inbound_detour_dynamic.go

示例3: Start

// Start starts the Point server, and return any error during the process.
// In the case of any errors, the state of the server is unpredicatable.
func (this *Point) Start() error {
	if this.port <= 0 {
		log.Error("Invalid port ", this.port)
		return BadConfiguration
	}

	err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
		err := this.ich.Listen(this.port)
		if err != nil {
			return err
		}
		log.Warning("Point server started on port ", this.port)
		return nil
	})
	if err != nil {
		return err
	}

	for _, detourHandler := range this.idh {
		err := detourHandler.Start()
		if err != nil {
			return err
		}
	}

	return nil
}
開發者ID:jun0205,項目名稱:v2ray-core,代碼行數:29,代碼來源:point.go

示例4: Dispatch

func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *alloc.Buffer, ray ray.OutboundRay) error {
	defer ray.OutboundInput().Release()
	defer ray.OutboundOutput().Close()

	var rec *protocol.ServerSpec
	var conn internet.Connection

	err := retry.Timed(5, 100).On(func() error {
		rec = this.serverPicker.PickServer()
		rawConn, err := internet.Dial(this.meta.Address, rec.Destination(), this.meta.StreamSettings)
		if err != nil {
			return err
		}
		conn = rawConn

		return nil
	})
	if err != nil {
		log.Error("VMess|Outbound: Failed to find an available destination:", err)
		return err
	}
	log.Info("VMess|Outbound: Tunneling request to ", target, " via ", rec.Destination)

	command := protocol.RequestCommandTCP
	if target.IsUDP() {
		command = protocol.RequestCommandUDP
	}
	request := &protocol.RequestHeader{
		Version: encoding.Version,
		User:    rec.PickUser(),
		Command: command,
		Address: target.Address(),
		Port:    target.Port(),
		Option:  protocol.RequestOptionChunkStream,
	}

	defer conn.Close()

	conn.SetReusable(true)
	if conn.Reusable() { // Conn reuse may be disabled on transportation layer
		request.Option.Set(protocol.RequestOptionConnectionReuse)
	}

	input := ray.OutboundInput()
	output := ray.OutboundOutput()

	var requestFinish, responseFinish sync.Mutex
	requestFinish.Lock()
	responseFinish.Lock()

	session := encoding.NewClientSession(protocol.DefaultIDHash)

	go this.handleRequest(session, conn, request, payload, input, &requestFinish)
	go this.handleResponse(session, conn, request, rec.Destination(), output, &responseFinish)

	requestFinish.Lock()
	responseFinish.Lock()
	return nil
}
開發者ID:ChoyesYan,項目名稱:v2ray-core,代碼行數:59,代碼來源:outbound.go

示例5: Start

func (this *InboundDetourHandler) Start() error {
	for _, ich := range this.ich {
		return retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
			err := ich.handler.Listen(ich.port)
			if err != nil {
				return err
			}
			return nil
		})
	}
	return nil
}
開發者ID:sign4bill,項目名稱:v2ray-core,代碼行數:12,代碼來源:inbound_detour.go

示例6: AcceptTCPConnections

func (this *DokodemoDoor) AcceptTCPConnections(tcpListener *net.TCPListener) {
	for this.accepting {
		retry.Timed(100, 100).On(func() error {
			connection, err := tcpListener.AcceptTCP()
			if err != nil {
				log.Error("Dokodemo failed to accept new connections: %v", err)
				return err
			}
			go this.HandleTCPConnection(connection)
			return nil
		})
	}
}
開發者ID:hackiechain,項目名稱:v2ray-core,代碼行數:13,代碼來源:dokodemo.go

示例7: AcceptConnections

func (server *SocksServer) AcceptConnections(listener *net.TCPListener) {
	for server.accepting {
		retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
			connection, err := listener.AcceptTCP()
			if err != nil {
				log.Error("Socks failed to accept new connection %v", err)
				return err
			}
			go server.HandleConnection(connection)
			return nil
		})

	}
}
開發者ID:kennshi,項目名稱:v2ray-core,代碼行數:14,代碼來源:socks.go

示例8: Start

// Start starts the Point server, and return any error during the process.
// In the case of any errors, the state of the server is unpredicatable.
func (vp *Point) Start() error {
	if vp.port <= 0 {
		log.Error("Invalid port %d", vp.port)
		return config.BadConfiguration
	}

	return retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
		err := vp.ich.Listen(vp.port)
		if err == nil {
			log.Warning("Point server started on port %d", vp.port)
			return nil
		}
		return err
	})
}
開發者ID:amazted,項目名稱:v2ray-core,代碼行數:17,代碼來源:point.go

示例9: AcceptConnections

func (handler *VMessInboundHandler) AcceptConnections(listener *net.TCPListener) error {
	for handler.accepting {
		retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
			connection, err := listener.AcceptTCP()
			if err != nil {
				log.Error("Failed to accpet connection: %s", err.Error())
				return err
			}
			go handler.HandleConnection(connection)
			return nil
		})

	}
	return nil
}
開發者ID:XUJiahua,項目名稱:v2ray-core,代碼行數:15,代碼來源:vmessin.go

示例10: Start

// Starts the inbound connection handler.
func (this *InboundDetourHandler) Start() error {
	for _, ich := range this.ich {
		err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
			err := ich.handler.Listen(ich.port)
			if err != nil {
				log.Error("Failed to start inbound detour on port %d: %v", ich.port, err)
				return err
			}
			return nil
		})
		if err != nil {
			return err
		}
	}
	return nil
}
開發者ID:adoot,項目名稱:v2ray-core,代碼行數:17,代碼來源:inbound_detour.go

示例11: Start

// Starts the inbound connection handler.
func (this *InboundDetourHandlerAlways) Start() error {
	for _, ich := range this.ich {
		err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
			err := ich.Start()
			if err != nil {
				log.Error("Failed to start inbound detour:", err)
				return err
			}
			return nil
		})
		if err != nil {
			return err
		}
	}
	return nil
}
開發者ID:ChoyesYan,項目名稱:v2ray-core,代碼行數:17,代碼來源:inbound_detour_always.go

示例12: accept

func (this *HttpProxyServer) accept() {
	for this.accepting {
		retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
			this.Lock()
			defer this.Unlock()
			if !this.accepting {
				return nil
			}
			tcpConn, err := this.tcpListener.AcceptTCP()
			if err != nil {
				log.Error("Failed to accept HTTP connection: ", err)
				return err
			}
			go this.handleConnection(tcpConn)
			return nil
		})
	}
}
開發者ID:ibmendoza,項目名稱:v2ray-core,代碼行數:18,代碼來源:http.go

示例13: AcceptConnections

func (this *SocksServer) AcceptConnections() {
	for this.accepting {
		retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
			this.tcpMutex.RLock()
			defer this.tcpMutex.RUnlock()
			if !this.accepting {
				return nil
			}
			connection, err := this.tcpListener.AcceptTCP()
			if err != nil {
				log.Error("Socks: failed to accept new connection: ", err)
				return err
			}
			go this.HandleConnection(connection)
			return nil
		})
	}
}
開發者ID:jun0205,項目名稱:v2ray-core,代碼行數:18,代碼來源:socks.go

示例14: AcceptTCPConnections

func (this *DokodemoDoor) AcceptTCPConnections() {
	for this.accepting {
		retry.Timed(100, 100).On(func() error {
			this.tcpMutex.RLock()
			defer this.tcpMutex.RUnlock()
			if !this.accepting {
				return nil
			}
			connection, err := this.tcpListener.AcceptTCP()
			if err != nil {
				log.Error("Dokodemo failed to accept new connections: %v", err)
				return err
			}
			go this.HandleTCPConnection(connection)
			return nil
		})
	}
}
開發者ID:ducktsmt,項目名稱:v2ray-core,代碼行數:18,代碼來源:dokodemo.go

示例15: AcceptConnections

func (this *VMessInboundHandler) AcceptConnections() error {
	for this.accepting {
		retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
			this.Lock()
			defer this.Unlock()
			if !this.accepting {
				return nil
			}
			connection, err := this.listener.AcceptTCP()
			if err != nil {
				log.Error("Failed to accpet connection: ", err)
				return err
			}
			go this.HandleConnection(connection)
			return nil
		})

	}
	return nil
}
開發者ID:airmao,項目名稱:v2ray-core,代碼行數:20,代碼來源:inbound.go


注:本文中的github.com/v2ray/v2ray-core/common/retry.Timed函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。