Ejemplo n.º 1
0
func (srv *Service) negotiateClientConn(mux frames.ChannelDialer, clientConn net.Conn) {
	srv.log.Printf("Dialing new muxed connection for client %v", clientConn.RemoteAddr())
	muxedConn, err := mux.Dial()
	if err == frames.ChannelsExhausted {
		srv.log.Printf("Ran out of channels when accepting new client connection from %v", clientConn.RemoteAddr())
		clientConn.Close()
	} else if err != nil {
		srv.log.Printf("Error with manager connection when accepting new client connection from %v: %v", clientConn.RemoteAddr(), err)
		srv.badMuxConn <- mux
		clientConn.Close()
	} else {
		// Start multiplexing the connection into mux.
		// TODO: Attempt to add deadlining when sending to the client.
		srv.manager.HandleNewConnection(muxedConn, clientConn)
		srv.log.Printf("Artemis client %v handed to connection manager", clientConn.RemoteAddr())
	}
}
Ejemplo n.º 2
0
func (srv *Service) muxMatcher() {
	var mux frames.ChannelDialer
	for {
		select {
		case newDialer := <-srv.newMuxConn:
			if mux != nil {
				srv.log.Printf("Closing old mux connection %v", mux.GetInfo())
				mux.Close()
			}
			mux = newDialer
			srv.log.Printf("Installed new mux connection %v", mux.GetInfo())
		case badDialer := <-srv.badMuxConn:
			if mux == badDialer {
				srv.log.Printf("Closing bad mux connection %v", mux.GetInfo())
				mux.Close()
				mux = nil
			}
		case clientConn := <-srv.newClientConn:
			if mux == nil {
				srv.log.Printf("Disconnected new client from %v: no mux client connected", clientConn.RemoteAddr())
				clientConn.Close()
				continue
			}
			go srv.negotiateClientConn(mux, clientConn)
		}
	}
}