Exemplo n.º 1
0
func (t *timer) runTimer(env *proc.Env) (err error) {
	for req, any := env.GetRequest(); any; req, any = env.GetRequest() {
		dur := req.(time.Duration)
		log.Debug("            .. sleep %v ..", dur)
		time.Sleep(dur)
		afterSleep := time.Now()
		env.PutReply(afterSleep)
	}

	return nil
}
Exemplo n.º 2
0
func (ic *incoming) runIncoming(env *proc.Env) error {
	ierr := ic.uniform.SetWriteInterrupt(env.Cancel)
	if ierr != nil {
		return ierr
	}

	// TODO: expand buf API and use it here
	for {
		// This is a kludge to try to avoid starving other goroutines in the event that we constantly
		// have something to read.  In particular, we might starve the outgoing goroutine in that case.
		runtime.Gosched()

		env.CancellationPoint()
		log.Debug("[ - reading up to %d bytes", cap(ic.inBuf)-len(ic.inBuf))
		rn, err := ic.visible.Read(ic.inBuf[len(ic.inBuf):cap(ic.inBuf)])
		if err != nil {
			return err
		}
		log.Debug("[-  read %d bytes", rn)
		ic.inBuf = ic.inBuf[:len(ic.inBuf)+rn]

		env.CancellationPoint()
		dn, sn := ic.decoder.UnshapeBytes(ic.pushBuf[len(ic.pushBuf):cap(ic.pushBuf)], ic.inBuf)
		log.Debug("[-- unshaped %d from %d bytes", dn, sn)
		ic.pushBuf = ic.pushBuf[:len(ic.pushBuf)+dn]
		ic.inBuf = ic.inBuf[:copy(ic.inBuf, ic.inBuf[sn:])]

		env.CancellationPoint()
		log.Debug("[   uniform: %d bytes", len(ic.pushBuf))
		wn, err := ic.uniform.Write(ic.pushBuf)
		if err != nil && err != io.ErrShortWrite {
			return err
		}
		ic.pushBuf = ic.pushBuf[:copy(ic.pushBuf, ic.pushBuf[wn:])]
	}
}
Exemplo n.º 3
0
func (sh *Shaper) runShaper(env *proc.Env) (err error) {
	select {
	case _ = <-env.Cancel:
		return env.ExitCanceled()
	}
}