コード例 #1
0
ファイル: utp.go プロジェクト: CaptainIlu/cloud-torrent
// first is true if this is the first time the send is acked. latency is
// calculated for the first ack.
func (s *send) Ack() (latency time.Duration, first bool) {
	s.resendTimer.Stop()
	if s.acked {
		return
	}
	s.acked = true
	s.conn.event.Broadcast()
	first = true
	latency = missinggo.MonotonicSince(s.started)
	return
}
コード例 #2
0
ファイル: send.go プロジェクト: skycoin/skycoin
func (s *send) timeoutResend() {
	mu.Lock()
	defer mu.Unlock()
	if missinggo.MonotonicSince(s.started) >= writeTimeout {
		s.timedOut()
		return
	}
	if s.acked.IsSet() || s.conn.destroyed.IsSet() {
		return
	}
	rt := s.conn.resendTimeout()
	s.resend()
	s.numResends++
	s.resendTimer.Reset(rt * time.Duration(s.numResends))
}
コード例 #3
0
ファイル: utp.go プロジェクト: CaptainIlu/cloud-torrent
func (s *send) timeoutResend() {
	if missinggo.MonotonicSince(s.started) >= writeTimeout {
		s.timedOut()
		return
	}
	s.conn.mu.Lock()
	defer s.conn.mu.Unlock()
	if s.acked || s.conn.closed {
		return
	}
	rt := s.conn.resendTimeout()
	go s.resend()
	s.numResends++
	s.resendTimer.Reset(rt * time.Duration(s.numResends))
}
コード例 #4
0
ファイル: send.go プロジェクト: skycoin/skycoin
// first is true if this is the first time the send is acked. latency is
// calculated for the first ack.
func (s *send) Ack() (latency time.Duration, first bool) {
	first = !s.acked.IsSet()
	if first {
		latency = missinggo.MonotonicSince(s.started)
	}
	if s.payload != nil {
		sendBufferPool.Put(s.payload[:0:minMTU])
		s.payload = nil
	}
	s.acked.Set()
	if s.resendTimer != nil {
		s.resendTimer.Stop()
		s.resendTimer = nil
	}
	return
}