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 } } }
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 } } }
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 } } }
func (x *resp) receiver(ep mangos.Endpoint) { rq := x.sock.RecvChannel() cq := x.sock.CloseChannel() outer: 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 continue outer } hops++ if len(m.Body) < 4 { m.Free() continue outer } 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 } } }
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() } } }