Exemple #1
0
extern void
disp_packet(			/* display a packet */
	register PACKHEAD	*p
)
{
	disp_result(DS_BUNDLE, packsiz(p->nr), (char *)p);
}
Exemple #2
0
extern int
serv_result(void)			/* get next server result and process it */
{
	static char	*buf = NULL;
	static int	bufsiz = 0;
	MSGHEAD	msg;
					/* read message header */
	if (fread((char *)&msg, sizeof(MSGHEAD), 1, stdin) != 1)
		goto readerr;
	if (msg.nbytes > 0) {		/* get the message body */
		if (msg.nbytes > bufsiz) {
			if (buf == NULL)
				buf = (char *)malloc(bufsiz=msg.nbytes);
			else
				buf = (char *)realloc((void *)buf,
						bufsiz=msg.nbytes);
			if (buf == NULL)
				error(SYSTEM, "out of memory in serv_result");
		}
		if (fread(buf, 1, msg.nbytes, stdin) != msg.nbytes)
			goto readerr;
	}
	switch (msg.type) {		/* process results */
	case DS_BUNDLE:
		if (msg.nbytes < sizeof(PACKHEAD) ||
				msg.nbytes != packsiz(((PACKHEAD *)buf)->nr))
			error(INTERNAL, "bad display packet from server");
		disp_bundle((PACKHEAD *)buf);
		break;
	case DS_ADDHOLO:
		if (msg.nbytes < sizeof(HDGRID)+2)
			error(INTERNAL, "bad holodeck record from server");
		add_holo((HDGRID *)buf, buf+sizeof(HDGRID),
			buf+sizeof(HDGRID)+strlen(buf+sizeof(HDGRID))+1);
		break;
	case DS_OUTSECT:
		do_outside = 1;
		goto noargs;
	case DS_EYESEP:
		if (msg.nbytes <= 1 || (eyesepdist = atof(buf)) <= FTINY)
			error(INTERNAL, "bad eye separation from server");
		break;
	case DS_STARTIMM:
	case DS_ENDIMM:
		if (!(imm_mode = (msg.type==DS_STARTIMM)))
			dev_flush();
#ifdef DEBUG
		{
			time_t	tnow = time(NULL);
			if (msg.type==DS_STARTIMM) tadd += tnow - tmodesw;
			else timm += tnow - tmodesw;
			tmodesw = tnow;
		}
#endif
		goto noargs;
	case DS_ACKNOW:
	case DS_SHUTDOWN:
		goto noargs;
	default:
		error(INTERNAL, "unrecognized result from server process");
	}
	return(msg.type);		/* return message type */
noargs:
	if (msg.nbytes) {
		sprintf(errmsg, "unexpected body with server message %d",
				msg.type);
		error(INTERNAL, errmsg);
	}
	return(msg.type);
readerr:
	if (feof(stdin))
		error(SYSTEM, "server process died");
	error(SYSTEM, "error reading from server process");
	return -1;  
}