• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang mangos.Endpoint类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/kildevaeld/projects/Godeps/_workspace/src/github.com/gdamore/mangos.Endpoint的典型用法代码示例。如果您正苦于以下问题:Golang Endpoint类的具体用法?Golang Endpoint怎么用?Golang Endpoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Endpoint类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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:kildevaeld,项目名称:projects,代码行数:25,代码来源:req.go


示例2: 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:kildevaeld,项目名称:projects,代码行数:8,代码来源:star.go


示例3: 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:kildevaeld,项目名称:projects,代码行数:8,代码来源:bus.go


示例4: 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:kildevaeld,项目名称:projects,代码行数:9,代码来源:push.go


示例5: 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:kildevaeld,项目名称:projects,代码行数:10,代码来源:pub.go


示例6: 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:kildevaeld,项目名称:projects,代码行数:10,代码来源:push.go


示例7: 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:kildevaeld,项目名称:projects,代码行数:10,代码来源:req.go


示例8: RemoveEndpoint

func (x *resp) 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:kildevaeld,项目名称:projects,代码行数:12,代码来源:respondent.go


示例9: 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.init.Do(func() {
		r.w.Add()
		go r.sender()
	})
	r.eps[ep.GetID()] = pe
	r.Unlock()
	go r.receiver(ep)
	go pe.sender()
}
开发者ID:kildevaeld,项目名称:projects,代码行数:13,代码来源:rep.go


示例10: AddEndpoint

func (x *resp) AddEndpoint(ep mangos.Endpoint) {
	x.init.Do(func() {
		x.w.Add()
		go x.sender()
	})
	peer := &respPeer{ep: ep, x: x, q: make(chan *mangos.Message, 1)}

	x.Lock()
	x.peers[ep.GetID()] = peer
	x.Unlock()

	go x.receiver(ep)
	go peer.sender()
}
开发者ID:kildevaeld,项目名称:projects,代码行数:14,代码来源:respondent.go


示例11: AddEndpoint

func (r *req) AddEndpoint(ep mangos.Endpoint) {

	r.init.Do(func() {
		r.w.Add()
		go r.resender()
	})

	pe := &reqEp{cq: make(chan struct{}), ep: ep}
	r.Lock()
	r.eps[ep.GetID()] = pe
	r.Unlock()
	go r.receiver(ep)
	r.w.Add()
	go r.sender(pe)
}
开发者ID:kildevaeld,项目名称:projects,代码行数:15,代码来源:req.go


示例12: AddEndpoint

func (x *pair) AddEndpoint(ep mangos.Endpoint) {
	peer := &pairEp{cq: make(chan struct{}), ep: ep}
	x.Lock()
	if x.peer != nil {
		// We already have a connection, reject this one.
		x.Unlock()
		ep.Close()
		return
	}
	x.peer = peer
	x.Unlock()

	x.w.Add()
	go x.receiver(peer)
	go x.sender(peer)
}
开发者ID:kildevaeld,项目名称:projects,代码行数:16,代码来源:pair.go


示例13: AddEndpoint

func (x *star) AddEndpoint(ep mangos.Endpoint) {
	x.init.Do(func() {
		x.w.Add()
		go x.sender()
	})
	depth := 16
	if i, err := x.sock.GetOption(mangos.OptionWriteQLen); err == nil {
		depth = i.(int)
	}
	pe := &starEp{ep: ep, x: x, q: make(chan *mangos.Message, depth)}
	x.Lock()
	x.eps[ep.GetID()] = pe
	x.Unlock()
	go pe.sender()
	go pe.receiver()
}
开发者ID:kildevaeld,项目名称:projects,代码行数:16,代码来源:star.go


示例14: receiver

func (x *pull) receiver(ep mangos.Endpoint) {
	rq := x.sock.RecvChannel()
	cq := x.sock.CloseChannel()
	for {

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

		select {
		case rq <- m:
		case <-cq:
			return
		}
	}
}
开发者ID:kildevaeld,项目名称:projects,代码行数:17,代码来源:pull.go


示例15: receiver

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

	rq := r.sock.RecvChannel()
	cq := r.sock.CloseChannel()

	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))

		hops := 0
		// Move backtrace from body to header.
		for {
			if hops >= r.ttl {
				m.Free() // ErrTooManyHops
				return
			}
			hops++
			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 rq <- m:
		case <-cq:
			m.Free()
			return
		}
	}
}
开发者ID:kildevaeld,项目名称:projects,代码行数:44,代码来源:rep.go


示例16: AddEndpoint

func (p *pub) AddEndpoint(ep mangos.Endpoint) {
	p.init.Do(func() {
		p.w.Add()
		go p.sender()
	})
	depth := 16
	if i, err := p.sock.GetOption(mangos.OptionWriteQLen); err == nil {
		depth = i.(int)
	}
	pe := &pubEp{ep: ep, p: p, q: make(chan *mangos.Message, depth)}
	pe.w.Init()
	p.Lock()
	p.eps[ep.GetID()] = pe
	p.Unlock()

	pe.w.Add()
	go pe.peerSender()
	go mangos.NullRecv(ep)
}
开发者ID:kildevaeld,项目名称:projects,代码行数:19,代码来源:pub.go


示例17: AddEndpoint

func (x *bus) AddEndpoint(ep mangos.Endpoint) {
	x.init.Do(func() {
		x.w.Add()
		go x.sender()
	})
	// Set our broadcast depth to match upper depth -- this should
	// help avoid dropping when bursting, if we burst before we
	// context switch.
	depth := 16
	if i, err := x.sock.GetOption(mangos.OptionWriteQLen); err == nil {
		depth = i.(int)
	}
	pe := &busEp{ep: ep, x: x, q: make(chan *mangos.Message, depth)}
	x.Lock()
	x.peers[ep.GetID()] = pe
	x.Unlock()
	go pe.peerSender()
	go pe.receiver()
}
开发者ID:kildevaeld,项目名称:projects,代码行数:19,代码来源:bus.go


示例18: receiver

func (x *resp) receiver(ep mangos.Endpoint) {

	rq := x.sock.RecvChannel()
	cq := x.sock.CloseChannel()

	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))
		hops := 0

		for {
			if hops >= x.ttl {
				m.Free() // ErrTooManyHops
				return
			}
			hops++
			if len(m.Body) < 4 {
				m.Free()
				continue
			}
			m.Header = append(m.Header, m.Body[:4]...)
			m.Body = m.Body[4:]
			if m.Header[len(m.Header)-4]&0x80 != 0 {
				break
			}
		}

		select {
		case rq <- m:
		case <-cq:
			m.Free()
			return
		}
	}
}
开发者ID:kildevaeld,项目名称:projects,代码行数:41,代码来源:respondent.go


示例19: receiver

func (s *sub) receiver(ep mangos.Endpoint) {

	rq := s.sock.RecvChannel()
	cq := s.sock.CloseChannel()

	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 rq <- m:
		case <-cq:
			m.Free()
			return
		default: // no room, drop it
			m.Free()
		}
	}
}
开发者ID:kildevaeld,项目名称:projects,代码行数:38,代码来源:sub.go



注:本文中的github.com/kildevaeld/projects/Godeps/_workspace/src/github.com/gdamore/mangos.Endpoint类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang mangos.Message类代码示例发布时间:2022-05-23
下一篇:
Golang mangos.Socket类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap