示例#1
0
文件: service.go 项目: 40a/vega
func (s *Service) cleanupConn(c net.Conn, data *clientData) {
	debugf("cleaning up conn to %s\n", c.RemoteAddr())

	s.lock.Lock()
	defer s.lock.Unlock()

	if data.closed {
		return
	}

	if data.lwt != nil {
		debugf("injecting lwt to %s\n", data.lwt.ReplyTo)
		name := data.lwt.ReplyTo
		data.lwt.ReplyTo = ""
		err := s.Registry.Push(name, data.lwt)

		if !errors.Equal(err, ENoMailbox) {
			debugf("lwt injection error: %s\n", err)
		}
	}

	close(data.done)

	if data.inflight != nil {
		for _, del := range data.inflight {
			del.Nack()
		}

		data.inflight = nil
	}

	for name, info := range data.ephemerals {
		s.Registry.Abandon(name)
		if info.lwt != nil {
			if info.lwt.ReplyTo == "" {
				continue
			}

			debugf("injecting ephemeral lwt to %s\n", info.lwt.ReplyTo)
			name := info.lwt.ReplyTo
			info.lwt.ReplyTo = ""
			err := s.Registry.Push(name, info.lwt)
			if !errors.Equal(err, ENoMailbox) {
				debugf("lwt ephemeral injection error: %#v\n", err)
			}
		}
	}

	data.session.Close()

	data.closed = true
}
示例#2
0
文件: service.go 项目: 40a/vega
func (s *Service) handleAbandon(c net.Conn, msg *Abandon, data *clientData) error {
	err := s.Registry.Abandon(msg.Name)
	if err != nil {
		return err
	}

	if info, ok := data.ephemerals[msg.Name]; ok {
		if info.lwt != nil {
			debugf("injecting ephemeral lwt 2 to %s\n", info.lwt.ReplyTo)
			name := info.lwt.ReplyTo
			info.lwt.ReplyTo = ""
			err := s.Registry.Push(name, info.lwt)
			if !errors.Equal(err, ENoMailbox) {
				debugf("lwt ephemeral injection 2 error: %#v\n", err)
			}
		}
	}

	_, err = c.Write([]byte{uint8(SuccessType)})
	return err
}