Exemplo n.º 1
0
func (s *sniffingRouter) RouteBackend() error {
	// route the next message from backend to frotnend,
	// blocking and flushing if necessary
	err := s.be.Next(&s.beBuf)
	if err != nil {
		return err
	}
	if proto.IsBackendKeyData(&s.beBuf) {
		beInfo, err := proto.ReadBackendKeyData(&s.beBuf)
		if err != nil {
			return err
		}
		s.backendPid = beInfo.BackendPid
		s.secretKey = beInfo.SecretKey
	}

	var clone core.Message
	clone.InitFromMessage(&s.beBuf)
	s.beCh <- &clone

	err = s.fe.Send(&s.beBuf)
	if !s.be.HasNext() {
		return s.fe.Flush()
	}
	return nil
}
Exemplo n.º 2
0
func (s *sniffingRouter) RouteFrontend() (err error) {
	// route the next message from frontend to backend,
	// blocking and flushing if necessary
	err = s.fe.Next(&s.feBuf)
	if err != nil {
		return
	}

	var clone core.Message
	clone.InitFromMessage(&s.feBuf)
	s.feCh <- &clone

	err = s.be.Send(&s.feBuf)
	if err != nil {
		return
	}
	if !s.fe.HasNext() {
		return s.be.Flush()
	}
	return
}