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 (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 } } }
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() } } }
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 } } }
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 (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 continue } 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 } } }