//doors/server7.c
#include	"unpipc.h"
#include	<math.h>
#include	"squareproc.h"
#include	"sqrtproc.h"

void
squareproc(void *cookie, char *dataptr, size_t datasize,
		   door_desc_t *descptr, size_t ndesc)
{
	squareproc_in_t	in;
	squareproc_out_t	out;
	
	memcpy(&in, dataptr, min(sizeof(in), datasize));
	printf("squareproc: thread id %ld, arg = %ld\n",
		   pr_thread_id(NULL), in.arg1);
	sleep(5);

	out.res1 = in.arg1 * in.arg1;
	Door_return((char *) &out, sizeof(out), NULL, 0);
}

void
sqrtproc(void *cookie, char *dataptr, size_t datasize,
		 door_desc_t *descptr, size_t ndesc)
{
	sqrtproc_in_t	in;
	sqrtproc_out_t	out;
	
	memcpy(&in, dataptr, min(sizeof(in), datasize));
	printf("sqrtproc: thread id %ld, arg = %ld\n",
		   pr_thread_id(NULL), in.arg1);
	sleep(5);

	out.res1 = sqrt((double) in.arg1);
	Door_return((char *) &out, sizeof(out), NULL, 0);
}
