public void mainLoop(boolean[] deactivated, int[] ext_disc_reason,
			RDPAdapter adapter) throws IOException, RdesktopException,
			OrderException, CryptoException {
		int[] type = new int[1];

		boolean disc = false; /* True when a disconnect PDU was received */
		boolean cont = true;

		RdpPacket_Localised data = null;

		while (!adapter.isStopped()) {
			try {
				data = this.receive(type);
				if (data == null)
					return;
			} catch (EOFException e) {
				return;
			}

			switch (type[0]) {

			case (Rdp.RDP_PDU_DEMAND_ACTIVE):
				logger.debug("Rdp.RDP_PDU_DEMAND_ACTIVE");
				// get this after licence negotiation, just before the 1st
				// order...
				NDC.push("processDemandActive");
				this.processDemandActive(data);
				// can use this to trigger things that have to be done before
				// 1st order
				logger.debug("ready to send (got past licence negotiation)");

				// /////// FIXME: virer frame.triggerReadyToSend();
				NDC.pop();
				deactivated[0] = false;
				break;

			case (Rdp.RDP_PDU_DEACTIVATE):
				// get this on log off
				deactivated[0] = true;
				this.stream = null; // ty this fix
				break;

			case (Rdp.RDP_PDU_DATA):
				logger.debug("Rdp.RDP_PDU_DATA");
				// all the others should be this
				NDC.push("processData");

				disc = this.processData(data, ext_disc_reason);
				NDC.pop();
				break;

			case 0:
				break; // 32K keep alive fix, see receive() - rdesktop 1.2.0.

			default:
				throw new RdesktopException("Unimplemented type in main loop :"
						+ type[0]);
			}

			if (disc)
				return;
		}
		return;
	}