func (x *Sieve) loop() {
	// Close out connection
	defer func() {
		close(x.k)
		x.Mute()
		x.dual.Mute()
	}()
	// Timeout ticker
	var tkr *time.Ticker
	var expchan <-chan time.Time
	if x.exp > 0 {
		tkr = time.NewTicker(x.exp)
		expchan = tkr.C
	}
	defer func() {
		if tkr != nil {
			tkr.Stop()
		}
	}()
	// Main loop
	var nrecv, nticks int
	for {
		select {
		case <-x.abrt:
			x.Frame.Println("Aborting sieve.")
			return
		case <-expchan:
			nticks++
			if nticks > 1 {
				x.Frame.Println("Breaking connection due to timeout.")
				return // Timeout with nothing send kills the connection
			}
		case q, ok := <-x.s:
			nticks = 0
			if !ok {
				return // s-channel closed, i.e. a Close on the sending HalfConn, kills the connection
			}
			nrecv++
			send := nrecv <= x.nok
			forceEOF := nrecv+1 > x.nok+x.ndrop
			if send {
				if _, ok := q.(eof); ok {
					x.Frame.Println("SIEVE ---> EOF") // ??
				}
				x.t.Send(q)
			}
			// OK tells conn.Write whether the message was delivered
			// EOF tells conn.Write whether the connection has ended after the write
			x.k <- feedback{OK: send, EOF: forceEOF}
			if forceEOF {
				x.Mute()
				x.dual.Mute()
			}
			//x.Printf("X=%-2d dlvr=%4v forceEOF=%4v (%d,%d)", nrecv, send, forceEOF, x.nok, x.ndrop)
		}
	}
}
// TIMEOUT MECHANISM:
// If the last packet was dropped, no eof has been reached and some time has
// passed since the last write to the connection, then kill the connection. (A
// user-side successful pre-EOF write, which was actually dropped, might cause
// a deadlock if it was the last write, as the recipient will block on read
// forever.) For this reason, we have a timeout mechanism inside the Sieve,
// which closes the connection after a period of inactivity.
TIMEOUT MECHANISM:
If the last packet was dropped, no eof has been reached and some time has
passed since the last write to the connection, then kill the connection. (A
user-side successful pre-EOF write, which was actually dropped, might cause
a deadlock if it was the last write, as the recipient will block on read
forever.) For this reason, we have a timeout mechanism inside the Sieve,
which closes the connection after a period of inactivity.
// TIMEOUT MECHANISM : // If the last packet was dropped no eof has been reached and some time has // passed since the last write to the connection then kill the connection . ( A // user - side successful pre - EOF write which was actually dropped might cause // a deadlock if it was the last write as the recipient will block on read // forever . ) For this reason we have a timeout mechanism inside the Sieve // which closes the connection after a period of inactivity .
func (x *Sieve) loop() {
	defer func() {
		close(x.k)
		x.Mute()
		x.dual.Mute()
	}()
	var tkr *time.Ticker
	var expchan <-chan time.Time
	if x.exp > 0 {
		tkr = time.NewTicker(x.exp)
		expchan = tkr.C
	}
	defer func() {
		if tkr != nil {
			tkr.Stop()
		}
	}()
	var nrecv, nticks int
	for {
		select {
		case <-x.abrt:
			x.Frame.Println("Aborting sieve.")
			return
		case <-expchan:
			nticks++
			if nticks > 1 {
				x.Frame.Println("Breaking connection due to timeout.")
				return 
			}
		case q, ok := <-x.s:
			nticks = 0
			if !ok {
				return 
			}
			nrecv++
			send := nrecv <= x.nok
			forceEOF := nrecv+1 > x.nok+x.ndrop
			if send {
				if _, ok := q.(eof); ok {
					x.Frame.Println("SIEVE ---> EOF") 
				}
				x.t.Send(q)
			}
			x.k <- feedback{OK: send, EOF: forceEOF}
			if forceEOF {
				x.Mute()
				x.dual.Mute()
			}
		}
	}
}
func ( x * Sieve ) loop ( ) { defer func ( ) { close ( x . k ) x . Mute ( ) x . dual . Mute ( ) } ( ) var tkr * time . Ticker var expchan <- chan time . Time if x . exp > 0 { tkr = time . NewTicker ( x . exp ) expchan = tkr . C } defer func ( ) { if tkr != nil { tkr . Stop ( ) } } ( ) var nrecv , nticks int for { select { case <- x . abrt : x . Frame . Println ( " " ) return case <- expchan : nticks ++ if nticks > 1 { x . Frame . Println ( " " ) return } case q , ok := <- x . s : nticks = 0 if ! ok { return } nrecv ++ send := nrecv <= x . nok forceEOF := nrecv + 1 > x . nok + x . ndrop if send { if _ , ok := q . ( eof ) ; ok { x . Frame . Println ( " " ) } x . t . Send ( q ) } x . k <- feedback { OK : send , EOF : forceEOF } if forceEOF { x . Mute ( ) x . dual . Mute ( ) } } } }
TIMEOUT MECHANISM:
If the last packet was dropped, no eof has been reached and some time has
passed since the last write to the connection, then kill the connection.
TIMEOUT MECHANISM : If the last packet was dropped no eof has been reached and some time has passed since the last write to the connection then kill the connection .
// Close out connection // Timeout ticker // Main loop // Timeout with nothing send kills the connection // s-channel closed, i.e. a Close on the sending HalfConn, kills the connection // ?? // OK tells conn.Write whether the message was delivered // EOF tells conn.Write whether the connection has ended after the write //x.Printf("X=%-2d dlvr=%4v forceEOF=%4v (%d,%d)", nrecv, send, forceEOF, x.nok, x.ndrop)