Example #1
0
func (r *receiver) ReceiveTimeout(timeout time.Duration) (rm ReceivedMessage, err error) {
	internal.Assert(r.buffer != nil, "Receiver is not open: %s", r)
	r.policy.Pre(r)
	defer func() { r.policy.Post(r, err) }()
	rmi, ok, timedout := timedReceive(r.buffer, timeout)
	switch {
	case timedout:
		return ReceivedMessage{}, Timeout
	case !ok:
		return ReceivedMessage{}, r.Error()
	default:
		return rmi.(ReceivedMessage), nil
	}
}
Example #2
0
// NewSender create a link sending to target.
// You must call snd.Open() before calling snd.Send().
func (s *session) Sender(v interface{}) (snd Sender, err error) {
	var settings LinkSettings
	switch v := v.(type) {
	case string:
		settings.Target = v
	case SenderSettings:
		settings = v.LinkSettings
	default:
		internal.Assert(false, "NewSender() want string or SenderSettings, got %T", v)
	}
	err = s.engine().InjectWait(func() error {
		l, err := makeLocalLink(s, true, settings)
		snd = newSender(l)
		return err
	})
	if err == nil {
		err = snd.Open()
	}
	return
}
Example #3
0
// Receiver opens a receiving link.
func (s *session) Receiver(v interface{}) (rcv Receiver, err error) {
	var settings ReceiverSettings
	switch v := v.(type) {
	case string:
		settings.Source = v
	case ReceiverSettings:
		settings = v
	default:
		internal.Assert(false, "NewReceiver() want string or ReceiverSettings, got %T", v)
	}
	err = s.engine().InjectWait(func() error {
		l, err := makeLocalLink(s, false, settings.LinkSettings)
		rcv = newReceiver(l)
		return err
	})
	rcv.SetCapacity(settings.Capacity, settings.Prefetch)
	if err == nil {
		err = rcv.Open()
	}
	return
}
Example #4
0
// Called in proton goroutine
func (r *receiver) handleDelivery(delivery proton.Delivery) {
	// FIXME aconway 2015-09-24: how can this happen if we are remote closed?
	if r.eLink.State().RemoteClosed() {
		localClose(r.eLink, r.eLink.RemoteCondition().Error())
		return
	}
	if delivery.HasMessage() {
		m, err := delivery.Message()
		if err != nil {
			localClose(r.eLink, err)
			return
		}
		internal.Assert(m != nil)
		r.eLink.Advance()
		if r.eLink.Credit() < 0 {
			localClose(r.eLink, internal.Errorf("received message in excess of credit limit"))
		} else {
			// We never issue more credit than cap(buffer) so this will not block.
			r.buffer <- ReceivedMessage{m, delivery, r}
		}
	}
}