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


Golang mangos.Endpoint類代碼示例

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


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

示例1: receiver

func (r *req) receiver(ep mangos.Endpoint) {
	rq := r.sock.RecvChannel()
	cq := r.sock.CloseChannel()

	for {
		m := ep.RecvMsg()
		if m == nil {
			break
		}

		if len(m.Body) < 4 {
			m.Free()
			continue
		}
		m.Header = append(m.Header, m.Body[:4]...)
		m.Body = m.Body[4:]

		select {
		case rq <- m:
		case <-cq:
			m.Free()
			break
		}
	}
}
開發者ID:rlhatcher,項目名稱:mangos,代碼行數:25,代碼來源:req.go

示例2: receiver

func (r *rep) receiver(ep mangos.Endpoint) {
	for {

		m := ep.RecvMsg()
		if m == nil {
			return
		}

		v := ep.GetID()
		m.Header = append(m.Header,
			byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
		// Move backtrace from body to header.
		for {
			if len(m.Body) < 4 {
				m.Free() // ErrGarbled
				return
			}
			m.Header = append(m.Header, m.Body[:4]...)
			m.Body = m.Body[4:]
			// Check for high order bit set (0x80000000, big endian)
			if m.Header[len(m.Header)-4]&0x80 != 0 {
				break
			}
		}

		select {
		case r.sock.RecvChannel() <- m:
		case <-r.sock.CloseChannel():
			m.Free()
			return
		}
	}
}
開發者ID:iwarsong,項目名稱:bearded,代碼行數:33,代碼來源:rep.go

示例3: receiver

func (s *sub) receiver(ep mangos.Endpoint) {
	for {
		var matched = false

		m := ep.RecvMsg()
		if m == nil {
			return
		}

		s.Lock()
		for _, sub := range s.subs {
			if bytes.HasPrefix(m.Body, sub) {
				// Matched, send it up.  Best effort.
				matched = true
				break
			}
		}
		s.Unlock()

		if !matched {
			m.Free()
			continue
		}

		select {
		case s.sock.RecvChannel() <- m:
		case <-s.sock.CloseChannel():
			m.Free()
			return
		default: // no room, drop it
			m.Free()
		}
	}
}
開發者ID:iwarsong,項目名稱:bearded,代碼行數:34,代碼來源:sub.go

示例4: AddEndpoint

func (x *surveyor) AddEndpoint(ep mangos.Endpoint) {
	peer := &surveyorP{ep: ep, x: x, q: make(chan *mangos.Message, 1)}
	x.Lock()
	x.peers[ep.GetID()] = peer
	go peer.receiver()
	go peer.sender()
	x.Unlock()
}
開發者ID:iwarsong,項目名稱:bearded,代碼行數:8,代碼來源:surveyor.go

示例5: RemoveEndpoint

func (x *star) RemoveEndpoint(ep mangos.Endpoint) {
	x.Lock()
	if peer := x.eps[ep.GetID()]; peer != nil {
		delete(x.eps, ep.GetID())
		close(peer.q)
	}
	x.Unlock()
}
開發者ID:lucmichalski,項目名稱:mangos,代碼行數:8,代碼來源:star.go

示例6: RemoveEndpoint

func (x *bus) RemoveEndpoint(ep mangos.Endpoint) {
	x.Lock()
	if peer := x.peers[ep.GetID()]; peer != nil {
		close(peer.q)
		delete(x.peers, ep.GetID())
	}
	x.Unlock()
}
開發者ID:rlhatcher,項目名稱:mangos,代碼行數:8,代碼來源:bus.go

示例7: AddEndpoint

func (r *req) AddEndpoint(ep mangos.Endpoint) {
	r.Lock()
	r.eps[ep.GetID()] = ep
	r.Unlock()
	r.senders.Add()
	go r.receiver(ep)
	go r.sender(ep)
}
開發者ID:iwarsong,項目名稱:bearded,代碼行數:8,代碼來源:req.go

示例8: RemoveEndpoint

func (x *surveyor) RemoveEndpoint(ep mangos.Endpoint) {
	x.Lock()
	defer x.Unlock()
	peer := x.peers[ep.GetID()]
	if peer == nil {
		return
	}
	delete(x.peers, ep.GetID())
}
開發者ID:iwarsong,項目名稱:bearded,代碼行數:9,代碼來源:surveyor.go

示例9: AddEndpoint

func (x *push) AddEndpoint(ep mangos.Endpoint) {
	pe := &pushEp{ep: ep, cq: make(chan struct{})}
	x.Lock()
	x.eps[ep.GetID()] = pe
	x.Unlock()
	x.w.Add()
	go x.sender(pe)
	go mangos.NullRecv(ep)
}
開發者ID:rlhatcher,項目名稱:mangos,代碼行數:9,代碼來源:push.go

示例10: RemoveEndpoint

func (p *pub) RemoveEndpoint(ep mangos.Endpoint) {
	id := ep.GetID()
	p.Lock()
	pe := p.eps[id]
	delete(p.eps, id)
	p.Unlock()
	if pe != nil {
		close(pe.q)
	}
}
開發者ID:rlhatcher,項目名稱:mangos,代碼行數:10,代碼來源:pub.go

示例11: RemoveEndpoint

func (x *push) RemoveEndpoint(ep mangos.Endpoint) {
	id := ep.GetID()
	x.Lock()
	pe := x.eps[id]
	delete(x.eps, id)
	x.Unlock()
	if pe != nil {
		close(pe.cq)
	}
}
開發者ID:rlhatcher,項目名稱:mangos,代碼行數:10,代碼來源:push.go

示例12: AddEndpoint

func (r *rep) AddEndpoint(ep mangos.Endpoint) {
	pe := &repEp{ep: ep, r: r, q: make(chan *mangos.Message, 2)}
	pe.w.Init()
	r.Lock()
	r.eps[ep.GetID()] = pe
	r.Unlock()
	pe.w.Add()
	go r.receiver(ep)
	go pe.sender()
}
開發者ID:iwarsong,項目名稱:bearded,代碼行數:10,代碼來源:rep.go

示例13: RemoveEndpoint

func (r *req) RemoveEndpoint(ep mangos.Endpoint) {
	id := ep.GetID()
	r.Lock()
	pe := r.eps[id]
	delete(r.eps, id)
	r.Unlock()
	if pe != nil {
		close(pe.cq)
	}
}
開發者ID:rlhatcher,項目名稱:mangos,代碼行數:10,代碼來源:req.go

示例14: receiver

func (x *push) receiver(ep mangos.Endpoint) {
	// In order for us to detect a dropped connection, we need to poll
	// on the socket.  We don't care about the results and discard them,
	// but this allows the disconnect to be noticed.  Note that we will
	// be blocked in this call forever, until the connection is dropped.
	for {
		if m := ep.RecvMsg(); m == nil {
			break
		}
	}
}
開發者ID:iwarsong,項目名稱:bearded,代碼行數:11,代碼來源:push.go

示例15: RemoveEndpoint

func (x *surveyor) RemoveEndpoint(ep mangos.Endpoint) {
	id := ep.GetID()

	x.Lock()
	peer := x.peers[id]
	delete(x.peers, id)
	x.Unlock()

	if peer != nil {
		close(peer.q)
	}
}
開發者ID:lucmichalski,項目名稱:mangos,代碼行數:12,代碼來源:surveyor.go


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