Exemplo n.º 1
0
func (p *Pumper) writing(ctx context.Context) {
	defer func() {
		if e := recover(); e != nil {
			switch v := e.(type) {
			case error:
				p.werr = v
			default:
				p.werr = errUnknownPanic
			}
		}

		p.wD.SetDone()
	}()

	for q := false; !q; {
		select {
		case <-ctx.Done():
			q = true
		case e := <-p.wQ:
			atomic.AddInt64(&p.stat.OutProcess, 1)
			p.writeMsg(e.t, e.m)
			bufpool.Put(e.m)
		}
	}
}
Exemplo n.º 2
0
// Copy the message data to the out-queue.
func (p *Pumper) Output(t MsgType, m Msg) {
	cp := bufpool.Get(len(m))
	copy(cp, m)
	select {
	case p.wQ <- msgEntry{t, cp}:
		atomic.AddInt64(&p.stat.OutTotal, 1)
	case <-p.stopD:
		bufpool.Put(cp)
	}
}
Exemplo n.º 3
0
// Try copy the message data to the out-queue.
func (p *Pumper) TryOutput(t MsgType, m Msg) bool {
	cp := bufpool.Get(len(m))
	copy(cp, m)
	select {
	case p.wQ <- msgEntry{t, cp}:
		atomic.AddInt64(&p.stat.OutTotal, 1)
		return true
	default:
		bufpool.Put(cp)
		return false
	}
}
Exemplo n.º 4
0
func (p *Pumper) work(ctx context.Context,
	rwqF context.CancelFunc, sn StopNotifier) {

	defer p.ending(rwqF, sn)

	for q := false; !q; {
		select {
		case <-ctx.Done():
			q = true
		case e := <-p.rQ:
			atomic.AddInt64(&p.stat.InProcess, 1)
			p.procMsg(ctx, e.t, e.m)
			bufpool.Put(e.m)
		case <-p.rD:
			q = true
		case <-p.wD:
			q = true
		}
	}
}