Exemplo n.º 1
0
static void *process(void *arg)
{
	char buf[SIZE*3/2];
	int ret;
	unsigned short w, h;
	Keda_BufInfo bufinfo;
	int fd;

	CD *cd = (CD *)arg;
	printf("new thread!\n");
	cd->nfd = netinit(cd->host, cd->port);
	
	while(cd->thread_stat){
		ret = Keda_CaptureGetBuf(0, &bufinfo);
		if (ret){
			printf ("%s: get buffer failed!\n", __FUNCTION__);
			continue;
		}
		w = bufinfo.imgW;
		h = bufinfo.imgH ; 

		if (bufinfo.bufvirt){
			ret = netsend(cd->nfd, bufinfo.bufvirt, w*h*3/2);
		}
		ret = Keda_CapturePutBuf(0, &bufinfo);
		usleep(1*1000); 
	}
	netexit(cd->nfd);
	pthread_exit(0);
}
Exemplo n.º 2
0
Arquivo: cs.c Projeto: brho/akaros
int main(int argc, char *argv[])
{
	int justsetname, ch;
	char ext[Maxpath], servefile[Maxpath];

	/* Make us an SCP with a 2LS */
	parlib_wants_to_be_mcp = FALSE;
	register_printf_specifier('F', printf_fcall, printf_fcall_info);

	argv0 = argv[0];
	justsetname = 0;
	setnetmtpt(mntpt, sizeof(mntpt), NULL);
	ext[0] = 0;
	while ((ch = getopt(argc, argv, "4df:nSx:")) != -1) {
		switch (ch) {
		case '4':
			ipv6lookups = 0;
			break;
		case 'd':
			debug = 1;
			break;
		case 'f':
			dbfile = optarg;
			break;
		case 'n':
			justsetname = 1;
			break;
		case 'S':
			server = 1;
			break;
		case 'x':
			setnetmtpt(mntpt, sizeof(mntpt), optarg);
			setext(ext, sizeof(ext), mntpt);
			break;
		default:
			usage();
			break;
		}
	}
	snprintf(servefile, sizeof(servefile), "#srv/cs%s", ext);
	snprintf(netndb, sizeof(netndb), "%s/ndb", mntpt);
	syscall(SYS_nunmount, (unsigned long)servefile, strlen(servefile),
	        (unsigned long)mntpt, strlen(mntpt));
	remove(servefile);

	ndbinit();
	netinit(0);

	if (!justsetname) {
		mountinit(servefile, mntpt);
		if (server)
			evnotify(0);
		io();
	}

	evexit(0);
}
Exemplo n.º 3
0
/*------------------------------------------------------------------------
 *  sysinit  --  initialize all Xinu data structeres and devices
 *------------------------------------------------------------------------
 */
LOCAL	sysinit()
{

	int i,j,len;
	struct pentry *pptr;	 /* null process entry */
	struct sentry *sptr;
	struct mblock *volatile mptr;

	numproc = 0;			/* initialize system variables */
	nextproc = NPROC-1;
	nextsem = NSEM-1;
	nextqueue = NPROC;		/* q[0..NPROC-1] are processes */

	memlist.mnext = mptr =		/* initialize free memory list */
	    (struct mblock *volatile) roundmb(__malloc_heap_start);
	mptr->mnext = (struct mblock *)NULL;
	mptr->mlen = len = (int) truncmb(RAMEND - NULLSTK - (unsigned)&__bss_end);
	__malloc_heap_start = (char *)mptr;
	__malloc_heap_end = __malloc_heap_start + len;
	kprintf_P(PSTR("Heap: %p of length %d\n"), mptr, len);
	
	for (i=0 ; i<NPROC ; i++)	/* initialize process table */
		proctab[i].pstate = PRFREE;

	/* initialize null process entry */
	pptr = &proctab[NULLPROC];
	pptr->pstate = PRCURR;
	for (j=0; j<6; j++)
		pptr->pname[j] = "nullp"[j];

	pptr->plimit = (unsigned char *)(RAMEND + 1) - NULLSTK;
	pptr->pbase = (unsigned char *) RAMEND;
	*pptr->pbase = (unsigned char)MAGIC; 	/* clobbers return, but proc 0 doesn't return */
	pptr->paddr = (int *) main;
	pptr->pargs = 0;
	pptr->pprio = 0;
	pptr->pregs[SSP_L] = lobyte((unsigned int)pptr->plimit);	/* for error checking */
	pptr->pregs[SSP_H] = hibyte((unsigned int)pptr->plimit);	/* for error checking */
	currpid = NULLPROC;

	for (i=0 ; i<NSEM ; i++) {	/* initialize semaphores */
		(sptr = &semaph[i])->sstate = SFREE;
		sptr->sqtail = 1 + (sptr->sqhead = newqueue());
	}

	rdytail = 1 + (rdyhead=newqueue());	/* initialize ready list */

	
#ifdef	MEMMARK
	kprintf("Memory marking\n");
	_mkinit();			/* initialize memory marking */
#else
	kprintf("Pool init\n");
	poolinit();			/* explicitly */
	pinit(MAXMSGS);
#endif

#ifdef	RTCLOCK
	kprintf("init RTC\n");
	clkinit();			/* initialize r.t.clock	*/
#endif

#ifdef NDEVS
	for ( i=0 ; i<NDEVS ; i++ ) {
		if (i>0) kprintf("init dev %d\n", i);
	    init(i);
	}
#endif

#ifdef	NNETS
//	kprintf("net init\n");
	netinit();
#endif

	return (OK);
}
Exemplo n.º 4
0
	// Multiplayer command line summary. Assume myconnectindex always = 0 for 192.168.1.2
	//
	// /n0 (mast/slav) 2 player:               3 player:
	// 192.168.1.2     game /n0                game /n0:3
	// 192.168.1.100   game /n0 192.168.1.2    game /n0 192.168.1.2
	// 192.168.1.4                             game /n0 192.168.1.2
	//
	// /n1 (peer-peer) 2 player:               3 player:
	// 192.168.1.2     game /n1 192.168.1.100  game /n1 192.168.1.100 192.168.1.4
	// 192.168.1.100   game 192.168.1.2 /n1    game 192.168.1.2 /n1 192.168.1.4
	// 192.168.1.4                             game 192.168.1.2 192.168.1.100 /n1
long initmultiplayersparms(long argc, char **argv)
{
	long i, j, daindex, portnum = NETPORT;

	initmultiplayers_reset();
	danetmode = 255; daindex = 0;

	// go looking for the port, if specified
	for (i=0;i<argc;i++) {
		if (argv[i][0] != '-' && argv[i][0] != '/') continue;
		if ((argv[i][1] == 'p' || argv[i][1] == 'P') && argv[i][2]) {
			char *p;
			j = strtol(argv[i]+2, &p, 10);
			if (!(*p) && j > 0 && j<65535) portnum = j;

			printf("mmulti: Using port %ld\n", portnum);
		}
	}

	netinit(portnum);

	for(i=0;i<argc;i++)
	{
		//if (((argv[i][0] == '/') || (argv[i][0] == '-')) &&
		//    ((argv[i][1] == 'N') || (argv[i][1] == 'n')) &&
		//    ((argv[i][2] == 'E') || (argv[i][2] == 'e')) &&
		//    ((argv[i][3] == 'T') || (argv[i][3] == 't')) &&
		//     (!argv[i][4]))
		//   { foundnet = 1; continue; }
		//if (!foundnet) continue;

		if ((argv[i][0] == '-') || (argv[i][0] == '/')) {
			if ((argv[i][1] == 'N') || (argv[i][1] == 'n') || (argv[i][1] == 'I') || (argv[i][1] == 'i'))
			{
				numplayers = 2;
				if (argv[i][2] == '0')
				{
					danetmode = 0;
					if ((argv[i][3] == ':') && (argv[i][4] >= '0') && (argv[i][4] <= '9'))
					{
						numplayers = (argv[i][4]-'0');
						if ((argv[i][5] >= '0') && (argv[i][5] <= '9')) numplayers = numplayers*10+(argv[i][5]-'0');
						printf("mmulti: %ld-player game\n", numplayers);
					}
					printf("mmulti: Master-slave mode\n");
				}
				else if (argv[i][2] == '1')
				{
					danetmode = 1;
					myconnectindex = daindex; daindex++;
					printf("mmulti: Peer-to-peer mode\n");
				}
				continue;
			}
			else if ((argv[i][1] == 'P') || (argv[i][1] == 'p')) continue;
		}

		if (isvalidipaddress(argv[i]))
		{
			if ((danetmode == 1) && (daindex == myconnectindex)) daindex++;
			for(j=0;argv[i][j];j++)
				if (argv[i][j] == ':')
					{ otherport[daindex] = htons((unsigned short)atol(&argv[i][j+1])); break; }
			otherip[daindex] = inet_addr(argv[i]);
			printf("mmulti: Player %ld at %s:%d\n",daindex,argv[i],ntohs(otherport[daindex]));
			daindex++;
			continue;
		}
		else
		{
			LPHOSTENT lph;
			unsigned short pt = htons(NETPORT);
			char *st = strdup(argv[i]); if (!st) continue;

			for(j=0;st[j];j++)
				if (st[j] == ':')
					{ pt = htons((unsigned short)atol(&st[j+1])); st[j] = 0; break; }
			if ((lph = gethostbyname(st)))
			{
				if ((danetmode == 1) && (daindex == myconnectindex)) daindex++;
				otherip[daindex] = *(long *)lph->h_addr;
				otherport[daindex] = pt;
				printf("mmulti: Player %ld at %s:%d (%s)\n",daindex,
						inet_ntoa(*(struct in_addr *)lph->h_addr),ntohs(pt),argv[i]);
				daindex++;
			} else printf("mmulti: Failed resolving %s\n",argv[i]);
			free(st);
			continue;
		}
	}
	if ((danetmode == 255) && (daindex)) { numplayers = 2; danetmode = 0; } //an IP w/o /n# defaults to /n0
	if ((numplayers >= 2) && (daindex) && (!danetmode)) myconnectindex = 1;
	if (daindex > numplayers) numplayers = daindex;

		//for(i=0;i<numplayers;i++)
		  //   printf("Player %d: %d.%d.%d.%d:%d\n",i,otherip[i]&255,(otherip[i]>>8)&255,(otherip[i]>>16)&255,((unsigned long)otherip[i])>>24,ntohs(otherport[i]));

	connecthead = 0;
	for(i=0;i<numplayers-1;i++) connectpoint2[i] = i+1;
	connectpoint2[numplayers-1] = -1;

	return (((!danetmode) && (numplayers >= 2)) || (numplayers == 2));
}
Exemplo n.º 5
0
/*------------------------------------------------------------------------
 *  sysinit  --  initialize all Xinu data structeres and devices
 *------------------------------------------------------------------------
 */
LOCAL
sysinit()
{
	static	long	currsp;
	int	i,j;
	struct	pentry	*pptr;
	struct	sentry	*sptr;
	struct	mblock	*mptr;

	numproc = 0;			/* initialize system variables */
	nextproc = NPROC-1;
	nextsem = NSEM-1;
	nextqueue = NPROC;		/* q[0..NPROC-1] are processes */

#ifdef X__COM32__
	puts_com32("sysinit()\n");
#endif
	
#ifdef __COM32__
	/* initialize free memory list */
	kprintf("com32topmem %d\n", (unsigned long) com32topmem);
	com32topmem = com32topmem - 1024*64; /* !!! we need some space fort this code */
	maxaddr =  (char*) com32topmem;
	kprintf("maxaddr     %d\n", (unsigned long) maxaddr);
	memlist.mnext = mptr = (struct mblock *) roundmb(&end);
	mptr->mnext = 0;
	mptr->mlen = (int) truncew((unsigned)maxaddr - (int)&end -
			NULLSTK);
#else
	/* initialize free memory list */
	/* PC version has to pre-allocate 640K-1024K "hole" */
	if (maxaddr+1 > HOLESTART) {
		memlist.mnext = mptr = (struct mblock *) roundmb(&end);
		mptr->mnext = (struct mblock *)HOLEEND;
		mptr->mlen = (int) truncew((unsigned) HOLESTART -
	     		 (unsigned)&end - 4);

		mptr = (struct mblock *) HOLEEND;
		mptr->mnext = 0;
		mptr->mlen = (int) truncew(maxaddr - HOLEEND - NULLSTK);
	} else {
		/* initialize free memory list */
		memlist.mnext = mptr = (struct mblock *) roundmb(&end);
		mptr->mnext = 0;
		mptr->mlen = (int) truncew((unsigned)maxaddr - (int)&end -
			NULLSTK);
	}
#endif
	
#ifdef X__COM32__
	puts_com32("sysinit() free memory list done\n");
#endif
	
	for (i=0 ; i<NPROC ; i++)	/* initialize process table */
		proctab[i].pstate = PRFREE;

#ifdef X__COM32__
	puts_com32("sysinit() proctab done\n");
#endif
	
	pptr = &proctab[NULLPROC];	/* initialize null process entry */
	pptr->pstate = PRCURR;
	for (j=0; j<7; j++)
		pptr->pname[j] = "prnull"[j];
	pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK;
	pptr->pbase = (WORD) maxaddr - 3;
	pptr->pesp = pptr->pbase-4;	/* for stkchk; rewritten before used */
	*( (int *)pptr->pbase ) = MAGIC;
	pptr->paddr = (WORD) nulluser;
	pptr->pargs = 0;
	pptr->pprio = 0;
	currpid = NULLPROC;

	for (i=0 ; i<NSEM ; i++) {	/* initialize semaphores */
		(sptr = &semaph[i])->sstate = SFREE;
		sptr->sqtail = 1 + (sptr->sqhead = newqueue());
	}

	rdytail = 1 + (rdyhead=newqueue());/* initialize ready list */

#ifdef X__COM32__
	puts_com32("sysinit() semaphores done\n");
#endif
	
#ifdef	MEMMARK
	_mkinit();			/* initialize memory marking */
#ifdef __COM32__
	puts_com32("sysinit()  memory marking done\n");
#endif
#endif

#ifdef	RTCLOCK
	clkinit();			/* initialize r.t.clock	*/
#ifdef __COM32__
	puts_com32("sysinit() rtc done\n");
#endif
#endif

#ifdef NDEVS
	for ( i=0 ; i<NDEVS ; i++ ) {
	    init(i);
	}
#ifdef __COM32__
	puts_com32("sysinit() devs done\n");
#endif	
#endif

#ifdef	NNETS
	netinit();
#ifdef __COM32__
	puts_com32("sysinit() netinit() done\n");
#endif
#endif

	return(OK);
}
Exemplo n.º 6
0
void
main(int argc, char **argv)
{
	int i, nets = 0;
	char *ann;

	rfork(RFNOTEG);
	formatinit();
	machinit();
	conf.confdev = "n";		/* Devnone */

	ARGBEGIN{
	case 'a':			/* announce on this net */
		ann = EARGF(usage());
		if (nets >= Maxnets) {
			fprint(2, "%s: too many networks to announce: %s\n",
				argv0, ann);
			exits("too many nets");
		}
		annstrs[nets++] = ann;
		break;
	case 'c':			/* use new, faster cache layout */
		oldcachefmt = 0;
		break;
	case 'f':			/* enter configuration mode first */
		conf.configfirst++;
		break;
	case 'm':			/* name device-map file */
		conf.devmap = EARGF(usage());
		break;
	default:
		usage();
		break;
	}ARGEND

	if (argc != 1)
		usage();
	conf.confdev = argv[0];	/* config string for dev holding full config */

	Binit(&bin, 0, OREAD);
	confinit();

	print("\nPlan 9 %d-bit cached-worm file server with %d-deep indir blks\n",
		sizeof(Off)*8 - 1, NIBLOCK);
	printsizes();

	qlock(&reflock);
	qunlock(&reflock);
	serveq = newqueue(1000, "9P service");	/* tunable */
	raheadq = newqueue(1000, "readahead");	/* tunable */

	mbinit();
	netinit();
	scsiinit();

	files = malloc(conf.nfile * sizeof *files);
	for(i=0; i < conf.nfile; i++) {
		qlock(&files[i]);
		qunlock(&files[i]);
	}

	wpaths = malloc(conf.nwpath * sizeof(*wpaths));
	uid = malloc(conf.nuid * sizeof(*uid));
	gidspace = malloc(conf.gidspace * sizeof(*gidspace));
	authinit();

	print("iobufinit\n");
	iobufinit();

	arginit();
	boottime = time(nil);

	print("sysinit\n");
	sysinit();

	/*
	 * Ethernet i/o processes
	 */
	netstart();

	/*
	 * read ahead processes
	 */
	newproc(rahead, 0, "rah");

	/*
	 * server processes
	 */
	for(i=0; i < conf.nserve; i++)
		newproc(serve, 0, "srv");

	/*
	 * worm "dump" copy process
	 */
	newproc(wormcopy, 0, "wcp");

	/*
	 * processes to read the console
	 */
	consserve();

	/*
	 * "sync" copy process
	 * this doesn't return.
	 */
	procsetname("scp");
	synccopy();
}
Exemplo n.º 7
0
Arquivo: cs.c Projeto: brho/akaros
static void rwrite(struct job *job, struct mfile *mf)
{
	int cnt, n;
	char *err;
	char *field[4];
	char curerr[64];

	err = 0;
	cnt = job->request.count;
	if (mf->qid.type & QTDIR) {
		err = "can't write directory";
		goto send;
	}
	if (cnt >= Maxrequest) {
		err = "request too long";
		goto send;
	}
	job->request.data[cnt] = 0;
	/*
	 *  toggle debugging
	 */
	if (strncmp(job->request.data, "debug", 5) == 0) {
		debug ^= 1;
		fprintf(stderr, "CS:debug %d", debug);
		goto send;
	}

	/*
	 *  toggle ipv6 lookups
	 */
	if (strncmp(job->request.data, "ipv6", 4) == 0) {
		ipv6lookups ^= 1;
		fprintf(stderr, "CS:ipv6lookups %d", ipv6lookups);
		goto send;
	}

	/*
	 *  toggle debugging
	 */
	if (strncmp(job->request.data, "paranoia", 8) == 0) {
		paranoia ^= 1;
		fprintf(stderr, "CS:paranoia %d", paranoia);
		goto send;
	}

	/*
	 *  add networks to the default list
	 */
	if (strncmp(job->request.data, "add ", 4) == 0) {
		if (job->request.data[cnt - 1] == '\n')
			job->request.data[cnt - 1] = 0;
		netadd(job->request.data + 4);
		readipinterfaces();
		goto send;
	}

	/*
	 *  refresh all state
	 */
	if (strncmp(job->request.data, "refresh", 7) == 0) {
		netinit(0 /*1*/);
		goto send;
	}

	/* start transaction with a clean slate */
	cleanmf(mf);

	/*
	 *  look for a general query
	 */
	if (*job->request.data == '!') {
		err = genquery(mf, job->request.data + 1);
		goto send;
	}

	if (debug)
		fprintf(stderr, "CS:write %s", job->request.data);
	if (paranoia)
		fprintf(stderr, "CS:write %s by %s", job->request.data,
			mf->user);

	/*
	 *  break up name
	 */
	n = getfields(job->request.data, field, 4, 1, "!");
	switch (n) {
	case 1:
		mf->net = strdup("net");
		mf->host = strdup(field[0]);
		break;
	case 4:
		mf->rem = strdup(field[3]);
	/* fall through */
	case 3:
		mf->serv = strdup(field[2]);
	/* fall through */
	case 2:
		mf->host = strdup(field[1]);
		mf->net = strdup(field[0]);
		break;
	}
	/*
	 *  do the first net worth of lookup
	 */
	if (lookup(mf) == 0) {
		snprintf(curerr, sizeof(curerr), "%r");
		err = curerr;
	}
send:
	job->reply.count = cnt;
	sendmsg(job, err);
}
Exemplo n.º 8
0
int
main(int argc, char **argv)
{
	int i;
	char commandLine[ MAX_STRING_CHARS ] = { 0 };

#ifndef DEDICATED
	/* SDL version check */

	/* Compile time */
#       if !SDL_VERSION_ATLEAST(MINSDL_MAJOR,MINSDL_MINOR,MINSDL_PATCH)
#               error A more recent version of SDL is required
#       endif

	/* Run time */
	const SDL_version *ver = SDL_Linked_Version();

#define MINSDL_VERSION \
	XSTRING(MINSDL_MAJOR) "." \
	XSTRING(MINSDL_MINOR) "." \
	XSTRING(MINSDL_PATCH)

	if(SDL_VERSIONNUM(ver->major, ver->minor, ver->patch) <
	   SDL_VERSIONNUM(MINSDL_MAJOR, MINSDL_MINOR, MINSDL_PATCH)){
		sysmkdialog(DT_ERROR,
			va(
				"SDL version " MINSDL_VERSION
				" or greater is required, "
				"but only version %d.%d.%d was found.",
			ver->major, ver->minor,
			ver->patch), "SDL library too old");
		Sys_Exit(1);
	}
	syssetenv("SDL_DISABLE_LOCK_KEYS", "1");
#endif
	Sys_PlatformInit( );
	/* Set the initial time base */
	sysmillisecs( );
	Sys_ParseArgs(argc, argv);
	Sys_SetBinaryPath(sysdirname(argv[ 0 ]));
	syssetdefaultinstallpath(DEFAULT_BASEDIR);

	/* Concatenate the command line for passing to cominit */
	for(i = 1; i < argc; i++){
		const qbool containsSpaces = strchr(argv[i], ' ') != NULL;
		if(containsSpaces)
			Q_strcat(commandLine, sizeof(commandLine), "\"");

		Q_strcat(commandLine, sizeof(commandLine), argv[ i ]);

		if(containsSpaces)
			Q_strcat(commandLine, sizeof(commandLine), "\"");

		Q_strcat(commandLine, sizeof(commandLine), " ");
	}

	cominit(commandLine);
	netinit();
	CON_Init();

	signal(SIGILL, Sys_SigHandler);
	signal(SIGFPE, Sys_SigHandler);
	signal(SIGSEGV, Sys_SigHandler);
	signal(SIGTERM, Sys_SigHandler);
	signal(SIGINT, Sys_SigHandler);

	for(;;){
		IN_Frame();
		comframe();
	}
	return 0;
}