⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diffs

📁 早期freebsd实现
💻
📖 第 1 页 / 共 2 页
字号:
The following diffs represent changes to attempt to reduce latencyby having servers start up and receive their connections by passingfile descriptors.  It is minorly better than the standard XNS serverson unix in that one can re-use an XNS SPP connection for additional RPCcalls; however, this is a performance issue that is not supported bythe unix clients and does not appreciably to appear to reduce latencyby anything except the first call to a unix server.  There are alsosome diffs to handle the fact that sprintf() calls no longer returna char *, but return a length.Common subdirectories: xns/bin and xns.newer/binCommon subdirectories: xns/compiler and xns.newer/compilerCommon subdirectories: xns/courierlib and xns.newer/courierlibCommon subdirectories: xns/daemon and xns.newer/daemonCommon subdirectories: xns/doc and xns.newer/docCommon subdirectories: xns/etc and xns.newer/etcCommon subdirectories: xns/examples and xns.newer/examplesCommon subdirectories: xns/include and xns.newer/includeCommon subdirectories: xns/lib and xns.newer/libCommon subdirectories: xns/man and xns.newer/manCommon subdirectories: xns/morexnslib and xns.newer/morexnslibCommon subdirectories: xns/xnscourier and xns.newer/xnscourierCommon subdirectories: xns/xnslib and xns.newer/xnslibCommon subdirectories: xns/courierlib/profiled and xns.newer/courierlib/profiledOnly in xns.newer/daemon: M.kOnly in xns.newer/daemon: daemon.hdiff -c -r xns/daemon/xnscourierd.c xns.newer/daemon/xnscourierd.c*** xns/daemon/xnscourierd.c	Mon Jan  5 08:43:09 1987--- xns.newer/daemon/xnscourierd.c	Tue Dec 22 17:03:56 1987****************** 34,42 ****--- 34,49 ----  #include <netns/sp.h>   #include <xnscourier/courier.h>	/* for lots of things */  #include <xnscourier/realcourierconnection.h> /* for CourierConnection */+ #include <xnscourier/courierdb.h>/* for lots of things */    struct sockaddr_ns here, dest;  + struct ServerTie *ServerList, *NextServerTie();+ char *copystr(), *malloc();+ fd_set ServerFdset, NullFdset;+ int NewConns;		/* Socket for new courier calls, others rehashed */+ int fd_for_returning;+ int fd_for_gettingback;  int CourierServerDebuggingFlag = 0;    ****************** 47,106 ****  Unspecified tid;				/* transaction ID */    - static void- reapchild()- {- 	union wait status;- - 	while (wait3(&status, WNOHANG, 0) > 0)- 		;- }-   main(argc, argv)  	int argc;  	char *argv[];  {! 	int s;! #ifndef DEBUGDBX! 	if (fork())! 		exit(0);! #endif /* DEBUGDBX */  	for (;;)! 		poller(argc,argv);  }  ! static! poller(argc,argv)! 	int argc;  	char *argv[];  {! 	int s, pid;  	extern int errno;    	here.sns_family = AF_NS;  	here.sns_addr.x_port = htons(IDPPORT_COURIER);  - #ifndef DEBUGDBX- 	for (s = 0; s < 20; s++)- 		(void) close(s);- 	(void) open("/", 0);- 	(void) dup2(0, 1);- 	(void) dup2(0, 2);- 	s = open("/dev/tty", 2);- 	if (s > 0) {- 		ioctl(s, TIOCNOTTY, 0);- 		close(s);- 	}- #endif /* DEBUGDBX */  	while ((s = socket(AF_NS, SOCK_SEQPACKET, 0)) < 0) {  		perror("xnscourierd: socket");  		sleep(5);  	}  	while (bind(s, &here, sizeof here) < 0) {  		perror("xnscourierd: bind");  		sleep(5);  	}- 	signal(SIGCHLD, reapchild);  	while (listen(s, 10) < 0) {  		perror("xnscourierd: listen");  		sleep(5);--- 54,109 ----  Unspecified tid;				/* transaction ID */      main(argc, argv)  	int argc;  	char *argv[];  {! 	int s, lim = getdtablesize();! 	void reapchild();! ! 	if (CourierServerDebuggingFlag == 0) {! 		if (fork())! 			exit(0);! 		for (s = 0; s < lim; s++)! 			(void) close(s);! 		(void) open("/", 0);! 		(void) dup2(0, 1);! 		(void) dup2(0, 2);! 		s = open("/dev/tty", 2);! 		if (s > 0) {! 			ioctl(s, TIOCNOTTY, 0);! 			close(s);! 		}! 	}! 	signal(SIGCHLD, reapchild);! 	StartServers();  	for (;;)! 		poller(s, argc, argv);  }  ! poller(s, argc, argv)! 	int s, argc;  	char *argv[];  {! 	int pid, nfds = getdtablesize(), on = 1;  	extern int errno;+ 	fd_set readfs, exceptfs;    	here.sns_family = AF_NS;  	here.sns_addr.x_port = htons(IDPPORT_COURIER);    	while ((s = socket(AF_NS, SOCK_SEQPACKET, 0)) < 0) {  		perror("xnscourierd: socket");  		sleep(5);  	}+ 	if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof on) < 0) {+ 		perror("xnscourierd: Keep-Alives");+ 	}+ 	NewConns = s;  	while (bind(s, &here, sizeof here) < 0) {  		perror("xnscourierd: bind");  		sleep(5);  	}  	while (listen(s, 10) < 0) {  		perror("xnscourierd: listen");  		sleep(5);****************** 111,116 ****--- 114,128 ----  		struct sockaddr_ns from;  		/* int padafter[100]; */  + 		FD_ZERO(&readfs);+ 		FD_SET(s, &readfs);+ 		FD_SET(fd_for_gettingback, &readfs);+ 		select(nfds, &readfs, 0, 0, 0);+ 		if (FD_ISSET(fd_for_gettingback, &readfs))+ 			garnerMessages(fd_for_gettingback);+ 		if (!(FD_ISSET(s, &readfs))) {+ 			continue;+ 		}  		s2 = accept(s, (caddr_t)&from, &fromlen);  		if (s2 < 0) {  			if (errno == EINTR)****************** 119,148 ****  			(void) close(s);  			return;	/* reset the world */  		}- #ifndef DEBUGDBX- 		if ((pid = fork()) < 0) {- 			perror("xnscourierd: Out of processes");- 			sleep(5);- 		}- 		else if (pid == 0) {- 			/* child */- 			signal(SIGCHLD, SIG_DFL);- 			close(s);	/* don't keep accepting */- 			doit(s2, &from);- 			exit(1);	/* can't get here? */- 			/*NOTREACHED*/- 		}- #else- 		signal(SIGCHLD, SIG_DFL);  		doit(s2, &from);- #endif- 		close(s2);  	}  	/*NOTREACHED*/  }    static CourierConnection connblock;    /*   * f is the socket on which we have gotten an SPP connection.   * who is the sockaddr_ns for the other end.--- 131,269 ----  			(void) close(s);  			return;	/* reset the world */  		}  		doit(s2, &from);  	}  	/*NOTREACHED*/  }  + StartServers()+ {+ 	register struct ServerTie *st, *st2;+ 	register struct courierdbent *db;+ 	int sv[2];+ 	int foundit = 0;+ + 	if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv)) {+ 		perror("socketpair");+ 		return; /*log error*/+ 	}+ 	fd_for_returning = sv[0];+ 	fd_for_gettingback = sv[1];+ + 	while ((db = getcourierdbent()) != NULL) {+ 		if (access(db->cr_serverbin, 1)) {+ 			/* Log this server as unobtainable */+ 			continue;+ 		}+ 		st = NextServerTie();+ 		st->st_db = *db;+ 		st->st_db.cr_serverbin = copystr(db->cr_serverbin);+ 		st->st_db.cr_description = copystr(db->cr_description);+ 		st->st_db.cr_programname = copystr(db->cr_programname);+ 		if (db->cr_threading != CR_EXEC) {+ 		    if (CourierServerDebuggingFlag)+ 			printf("Got a threaded server(%s): %s\n",+ 				st->st_db.cr_programname,+ 				st->st_db.cr_serverbin);+ 		    if (db->cr_threading == CR_WAIT) {+ 			for (st2 = ServerList; st2; st2 = st2->st_next)+ 			    if (st2 != st &&+ 				st2->st_db.cr_threading == CR_WAIT &&+ 				strcmp( st->st_db.cr_serverbin,+ 					    st2->st_db.cr_serverbin) == 0) {+ 				     foundit = 1;+ 				     st->st_fd = st2->st_fd;+ 			    }+ 		    }+ 		    if (foundit)+ 			foundit = 0;+ 		    else+ 			execServerSetup(st);+ 		}+ 	}+ }+ + execServerSetup(st)+ register struct ServerTie *st;+ {+ 	static char *argv[2], arg0[10]; + 	int lim = getdtablesize(), i, sv[2];+ + 	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv))+ 		{ /* Log error */return;  }+ 	st->st_fd = sv[0];+ fork_again:+ 	switch(st->st_pid = vfork()) {+ 	case -1:+ 		/* Log Error */+ 		sleep (15);+ 		goto fork_again;+ 	case 0: /* Child */+ 		for (i = 0; i < lim; i++) {+ 			if (CourierServerDebuggingFlag && i < 3)+ 				continue;+ 			if (i == sv[1])+ 				continue;+ 			if (i == fd_for_returning)+ 				continue;+ 		}+ 		sprintf(arg0, "*%d,%d", sv[1], fd_for_returning);+ 		argv[0] = arg0; argv[1] = 0;+ 		execv(st->st_db.cr_serverbin, argv);+ 		_exit(0);+ 	}+ 	close(sv[1]);+ }+ + void+ reapchild()+ {+ 	union wait status;+ 	int pid;+ 	register struct ServerTie *st;+ + 	while ((pid = wait3(&status, WNOHANG, 0)) > 0) {+ 		register struct ServerTie *st = ServerList;+ 		for (st = ServerList; st; st = st->st_next) {+ 			if ((st->st_pid == pid) &&+ 			    (st->st_db.cr_threading == CR_WAIT)) {+ 				close(st->st_fd);+ 				execServerSetup(st);+ 			}+ 		}   + 	}+ }+ +   static CourierConnection connblock;  + garnerMessages(fd)+ int fd;+ {+ 	Unspecified buf[512], *bp; + 	register CourierConnection *f = _serverConnection;+ 	int newfd, buflen;+ 	LongCardinal programnum;+ 	Cardinal versionnum;+ 	int skipcount;+ 	+ 	/* set up the CourierConnection data */+ 	_serverConnection = &connblock;+ 	buflen = sizeof(buf);+ 	if (garner_fd(fd, &newfd, buf, &buflen) < 0)+ 		return;+ 	bp = buf;+ 	bp += internalize_LongCardinal(&programnum, bp);+ 	bp += internalize_Cardinal(&versionnum, bp);+ 	skipcount = *(unsigned short *) bp;+ 	bp++;+ 	_serverConnection->fd = newfd;+ 	_serverConnection->state = inprogress;+ 	_serverConnection->bdtstate = wantdata;+ 	ServerExecCourierProgram(programnum, versionnum, skipcount,+ 			   bp);+ 	close (newfd);+ }  /*   * f is the socket on which we have gotten an SPP connection.   * who is the sockaddr_ns for the other end.****************** 170,186 ****  	CourierWrite(_serverConnection, (bp-skippedwords), skippedwords,  		     0, (Unspecified*) NULL);  	/* read and process a connection message */! 	for (;;) {! 		skipcount = LookAheadCallMsg(&programnum, &versionnum,! 					     skippedwords);! 		if (skipcount < 0) fatal("connection timed out");! #ifdef DEBUG! 		fprintf(stderr,"Chaining to %d(%d).  Skipcount =%d\n",! 			programnum, versionnum, skipcount);! #endif! 		ExecCourierProgram(programnum, versionnum, skipcount,! 				   skippedwords);  	}  }    --- 291,365 ----  	CourierWrite(_serverConnection, (bp-skippedwords), skippedwords,  		     0, (Unspecified*) NULL);  	/* read and process a connection message */! 	skipcount = LookAheadCallMsg(&programnum, &versionnum,! 				     skippedwords);! 	if (skipcount < 0) fatal("connection timed out");! 	if (CourierServerDebuggingFlag)! 	    fprintf(stderr,"Chaining to %d(%d).  Skipcount =%d\n",! 		programnum, versionnum, skipcount);! 	ServerExecCourierProgram(programnum, versionnum, skipcount,! 			   skippedwords);! 	close (f);! }! ! ServerExecCourierProgram(programnum, versionnum, skipcount, skippedwords)! 	LongCardinal programnum;! 	Cardinal versionnum;! 	int skipcount;! 	Unspecified skippedwords[];! /*!  * Exec the appropriate courier program, passing it asciized skippedwords!  * in the argument list.!  * Does not return unless the exec failed or the server was not found.!  * If the server cannot be EXECed, then the appropriate message is sent!  * back on the wire and the current message is flushed.!  */! {! 	struct courierdbent *cdbent;! 	char *argv[12];! 	int i, argc;! 	extern char *malloc();! 	char tmpbuf[1024];! 	char *path;! ! 	Unspecified databuf[12] , *dp = databuf;! 	register struct ServerTie *st = ServerList;! ! 	for (; st; st = st->st_next) {! 		if (st->st_db.cr_programnumber != programnum)! 			continue;! 		if (st->st_db.cr_version != versionnum)! 			continue;! 		if (st->st_db.cr_threading != CR_EXEC) {! 			dp = databuf;! 			dp += externalize_LongCardinal(dp, &programnum);! 			dp += externalize_Cardinal(dp, &versionnum);! 			dp += externalize_Cardinal(dp, &skipcount);! 			for (i = 0; i++; i < skipcount)! 				*dp++ = skippedwords[i];! 			pass_fd_rights(st->st_fd, _serverConnection->fd,! 				databuf, (dp - databuf) * sizeof(Unspecified));! 			if (st->st_db.cr_threading == CR_NOWAIT) {! 				close(st->st_fd);! 				execServerSetup(st);! 			}! 			return;! 		}! 		break;  	}+ 	/* Have to vfork and exec, but don't trust rest of library+ 	   for now */+ fork_again:+ 	switch (fork()) {+ 	case -1:+ 		sleep(15);+ 		goto fork_again;+ 	case 0:+ 		ExecCourierProgram(programnum,+ 					versionnum, skipcount, skippedwords);+ 		_exit(0);+ 	}+   }    ****************** 190,192 ****--- 369,416 ----  	(void) fprintf(stderr, "xnscourierd: %s.\n", msg);  	exit(1);  }+ #define LOTS 8192+ + char *+ copystr(cp)+ 	char *cp;+ {+ 	static char *base;+ 	static int remaining;+ 	int len;+ + 	if (cp == 0)+ 		return (0);+ + 	len = strlen(cp) + 1;+ 	if (len > remaining) {+ 		base = malloc (LOTS);+ 		remaining = LOTS;+ 	}+ 	if (len > LOTS) len = LOTS - 1;+ 	strncpy(base, cp, len);+ 	cp = base;+ 	base += len;+ 	return (cp);+ }+ + struct ServerTie *+ NextServerTie()+ {+ 	static int remaining;+ 	static struct ServerTie *base, *last;+ 	register struct ServerTie *result;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -