本文整理匯總了Golang中github.com/go-mangos/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
}
}
}
示例2: 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()
}
示例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()
}
示例4: 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()
}
示例5: 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)
}
示例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)
}
}
示例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)
}
}
示例8: 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)
}
}
示例9: 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)
}
}
示例10: AddEndpoint
func (x *star) AddEndpoint(ep mangos.Endpoint) {
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()
}
示例11: 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()
}
示例12: 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()
}
示例13: AddEndpoint
func (p *pub) AddEndpoint(ep mangos.Endpoint) {
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)
}
示例14: 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)
}
示例15: AddEndpoint
func (x *bus) AddEndpoint(ep mangos.Endpoint) {
// 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()
}