SshChannelMessage processMessages(MessageObserver messagefilter)
			throws SshException, EOFException {

		SshChannelMessage msg;

		/**
		 * Collect the next channel message from the connection protocol
		 */
		msg = (SshChannelMessage) ms.nextMessage(messagefilter, 0);

		switch (msg.getMessageId()) {

		case SSH_MSG_WINDOW_ADJUST:

			try {

				remotewindow.adjust(msg.readInt());

				if (Log.isDebugEnabled()) {
					Log.debug(this, "Applied window adjust window="
							+ remotewindow.available());
				}
			} catch (IOException ex) {
				throw new SshException(SshException.INTERNAL_ERROR, ex);
			}
			break;

		case SSH_MSG_CHANNEL_DATA:

			try {
				int length = (int) msg.readInt();
				processStandardData(length, msg);
			} catch (IOException e) {
				throw new SshException(SshException.INTERNAL_ERROR, e);
			}
			break;

		case SSH_MSG_CHANNEL_EXTENDED_DATA:
			try {
				int type = (int) msg.readInt();
				int length = (int) msg.readInt();
				processExtendedData(type, length, msg);
			} catch (IOException ex) {
				throw new SshException(SshException.INTERNAL_ERROR, ex);
			}
			break;

		/**
		 * We dont remove these messages because other threads may be evaluating
		 * the messages at the same time
		 */
		case SSH_MSG_CHANNEL_CLOSE:
			checkCloseStatus(true);
			throw new EOFException("The channel is closed");

		case SSH_MSG_CHANNEL_EOF:
			throw new EOFException("The channel is EOF");

			/**
			 * Just return
			 */
		default:
			break;
		}

		return msg;
	}