/********************************************************************
 ** NETWORK FILE SYSTEM SERVICE
 **
 ** (c) Spak, Darrell Tam, c9107253@ee.newcastle.edu.au (1994)
 ** phone (Australia) 049-829-710
 **                    49-829-710
 ** (c) SST Jan-Feb-Mar 1994
 **
 ** "WAITCHAR"
 **
 ** TABS to 4
 ********************************************************************/

#include "/snd/everything.h"
#include <st/st_proto.h>

#include "nfsinternal.h"
#include "nfsglobs_protos.h"


#define IFH_WAITCHARMSG_SIZE (sizeof(struct IFHWaitCharMsg))
struct IFHWaitCharMsg {
	struct IFHDosMsg	dm;
	struct NFSStdReturn waitcharret;
};

/********************************************************************/
	static void free_retret_waitchar(struct PktMsgRecv *pmr)
/********************************************************************/
{
#ifdef DEBUG
	fpf(out, "nfs_waitchar: Freeing memory\n");
#endif
	FreeMem((void *)pmr->user.user2, IFH_WAITCHARMSG_SIZE);
	FREE_PKTMSGRECV(pmr);			/* 	everything the server sent */
}


/********************************************************************/
	static void handle_waitchar_dos(struct IFHWaitCharMsg *wcpm)
/********************************************************************/
{
struct PktMsgRecv *pmr = wcpm->dm.pktmsg;
#ifdef DEBUG
	fpf(out, "nfs_waitchar: result going home\n");
#endif
	wcpm->waitcharret.remote_res1 = IFHMSG_RES1(&wcpm->dm);
	wcpm->waitcharret.remote_res2 = IFHMSG_RES2(&wcpm->dm);
	PUT_STDMSG(&pmr->pm.smsg, pmr->dmaport, TYPE_INTERNAL_SEND);
}


/********************************************************************/
	void *srv_waitchar(struct PktMsgRecv *pmr)
/********************************************************************/
{
struct NFSWaitChar		*req = (void *)pmr->req_body;
struct InternalFH		*ifh =
	GET_INTERNALFH(req->remote_ifh, req->remote_majic);
struct IFHWaitCharMsg	*wcpm;
	if(!ifh) return(&nfs_res_notfound);		/* filehandle doesn't exist! */

	ACT_ALLOCMSG_THINGY(wcpm, IFH_WAITCHARMSG_SIZE);

#ifdef DEBUG
	fpf(out, "nfs_waitchar: timeout=%ld\n", req->timeout);
#endif

	ACT_INIT_RETURN_PMR(pmr, free_retret_waitchar, wcpm, &wcpm->waitcharret, req);
	wcpm->dm.dosmsg.sp.sp_Pkt.dp_Type = ACTION_WAIT_CHAR;
	wcpm->dm.dosmsg.sp.sp_Pkt.dp_Arg1 = req->timeout;
	ACT_PUT_IFHDOSMSG(wcpm, dosport, handle_waitchar_dos, ifh, pmr);
	return(NULL);
}
