/* delete_port.c */

/*		Copyright © 1989 by Donald T. Meyer, Stormgate Software
 *		All Rights Reserved
 */



#include "rxil.h"



/* NAME
 *		RxilDeletePort
 *
 * SYNOPSIS
 *		RxilDeletePort( port );
 *
 *		struct MsgPort *port;
 *
 * FUNCTION
 *		This will safely delete a message port used to receive commands
 *		from ARexx.
 *		This is acomplished by setting a failure return code and
 *		replying the message if it is from ARexx.
 *		If the message is not from ARexx, it is merely replied.
 *
 *		WARNING: If the port was/is used to receive replys, there must
 *		be no chance of a reply being pending when this function is
 *		called!
 *
 * INPUTS
 *		port = pointer to a MsgPort.  Normally one that was opened
 *			for receiving ARexx commands.
 *
 * RESULT
 *		None
 *
 * SIDES
 *
 * HISTORY
 *		01-Aug-89	Creation.
 *
 * BUGS
 *
 * SEE ALSO
 *
 */
 
void RxilDeletePort( struct MsgPort *port )
{
	struct RexxMsg *rexxmsg;
 
 
	Forbid();
 
	while( rexxmsg = (struct RexxMsg *)GetMsg( port ) )
	{
		if(  IsRexxMsg( rexxmsg )  )
		{
			/* Set failure code */
			rexxmsg->rm_Result1 = RC_FATAL;
			rexxmsg->rm_Result2 = 0;
		}
 
		ReplyMsg( (struct Message *)rexxmsg );
	}
 
	DeletePort( port );
 
	Permit();
}

