當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Message.Dup方法代碼示例

本文整理匯總了Golang中github.com/gdamore/mangos.Message.Dup方法的典型用法代碼示例。如果您正苦於以下問題:Golang Message.Dup方法的具體用法?Golang Message.Dup怎麽用?Golang Message.Dup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/gdamore/mangos.Message的用法示例。


在下文中一共展示了Message.Dup方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: broadcast

func (x *bus) broadcast(m *mangos.Message, sender uint32) {

	x.Lock()
	for id, pe := range x.eps {
		if m != nil {
			if sender == id {
				continue
			}
			m = m.Dup()
		}
		select {
		case pe.q <- m:
		default:
			// No room on outbound queue, drop it.
			// Note that if we are passing on a linger/shutdown
			// notification and we can't deliver due to queue
			// full, it means we will wind up waiting the full
			// linger time in the lower sender.  Its correct, if
			// suboptimal, behavior.
			if m != nil {
				m.Free()
			}
		}
	}
	x.Unlock()
}
開發者ID:iwarsong,項目名稱:bearded,代碼行數:26,代碼來源:bus.go

示例2: SendHook

func (r *req) SendHook(m *mangos.Message) bool {

	if r.raw {
		// Raw mode has no automatic retry, and must include the
		// request id in the header coming down.
		return true
	}
	r.Lock()
	defer r.Unlock()

	// We need to generate a new request id, and append it to the header.
	r.reqid = r.nextID()
	v := r.reqid
	m.Header = append(m.Header,
		byte(v>>24), byte(v>>16), byte(v>>8), byte(v))

	r.reqmsg = m.Dup()

	// Schedule a retry, in case we don't get a reply.
	if r.retry > 0 {
		r.waker.Reset(r.retry)
	} else {
		r.waker.Stop()
	}

	r.sock.SetRecvError(nil)

	return true
}
開發者ID:rlhatcher,項目名稱:mangos,代碼行數:29,代碼來源:req.go

示例3: broadcast

func (x *star) broadcast(m *mangos.Message, sender *starEp) {

	x.Lock()
	for _, pe := range x.eps {
		if sender == pe {
			continue
		}
		if m != nil {
			m = m.Dup()
		}
		select {
		case pe.q <- m:
		default:
			// No room on outbound queue, drop it.
			if m != nil {
				m.Free()
			}
		}
	}
	x.Unlock()

	// Grab a local copy and send it up if we aren't originator
	if m != nil {
		if sender != nil {
			select {
			case x.sock.RecvChannel() <- m:
			case <-x.sock.CloseChannel():
				m.Free()
				return
			default:
				// No room, so we just drop it.
				m.Free()
			}
		} else {
			// Not sending it up, so we need to release it.
			m.Free()
		}
	}
}
開發者ID:iwarsong,項目名稱:bearded,代碼行數:39,代碼來源:star.go

示例4: sender

func (x *surveyor) sender() {
	defer x.w.Done()
	sq := x.sock.SendChannel()
	cq := x.sock.CloseChannel()
	for {
		var m *mangos.Message
		select {
		case m = <-sq:
		case <-cq:
			return
		}

		x.Lock()
		for _, pe := range x.peers {
			m := m.Dup()
			select {
			case pe.q <- m:
			default:
				m.Free()
			}
		}
		x.Unlock()
	}
}
開發者ID:lucmichalski,項目名稱:mangos,代碼行數:24,代碼來源:surveyor.go


注:本文中的github.com/gdamore/mangos.Message.Dup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。