Beispiel #1
0
void
main(void)
{
	int64_t a2000, a500, tStart, tEnd;
	if (!atnotify(printFirst, 1) || !atnotify(failOnSecond, 1)){
		fprint(2, "%r\n");
		exits("atnotify fails");
	}

	alarm(2000);
	a2000 = nsec();
	alarm(500);
	a500 = nsec();
	tStart = nsec();
	sleep(1000);
	tEnd = nsec();

	if(verbose)
		fprint(2, "%d: set alarm(2000)@%lld then alarm(500)@%lld; elapsed in sleep() %lld nanosecond\n", getpid(), a2000, a500, tEnd-tStart);

	if(tEnd-tStart > 1200 * 1000 * 1000){
		print("FAIL: should sleep less\n");
		exits("FAIL");
	}

	if(tEnd-tStart < 800 * 1000 * 1000){
		print("FAIL: should sleep more\n");
		exits("FAIL");
	}

	print("PASS\n");
	exits("PASS");
}
Beispiel #2
0
void
main(int argc, char **argv)
{
	char buf[512];
	vlong size;
	vlong pos;
	vlong ns;
	int fd;
	int i;

	if(argc != 2) {
		fprint(2, "usage: %s /dev/sd??/data\n", argv[0]);
		exits("usage");
	}
	
	srand(time(0));
	fd = open(argv[1], OREAD);
	if(fd < 0)
		sysfatal("open: %r");
	size = seek(fd, 0, 2) / 512;
	ns = nsec();
	for(i=0;i<100;i++) {
		pos = (vlong)(frand() * size);
		if(pread(fd, buf, 512, 512 * pos) < 512)
			sysfatal("read: %r");
	}
	ns = nsec() - ns;
	print("%.3g\n", ((double)ns)/100000000);
	exits(nil);
}
Beispiel #3
0
void
spawnWaiter(Lock *l)
{
	int pid;
	int64_t start;

	switch((pid = rfork(RFMEM|RFPROC|RFNOWAIT)))
	{
		case 0:
			/* wait for the alwaysLocked to be locked by the main process */
			qlock(&rl);
			while(resInWaiter == 0xff)
				rsleep(&rStart);

			start = nsec();
			resInWaiter = lockt(l, 6000);
			elapsedInWaiter = (nsec() - start) / (1000 * 1000);
			if(verbose)
				print("lockt returned %d, elapsed = %d ms\n", resInWaiter, elapsedInWaiter);

			rwakeup(&rCompleted);
			qunlock(&rl);

			exits(0);
			break;
		case -1:
			print("spawnWaiter: %r\n");
			exits("rfork fails");
			break;
		default:
			if(verbose)
				print("spawn waiter %d\n", pid);
			break;
	}
}
Beispiel #4
0
void
main(void)
{
	int ret = 0; // success
	uint64_t start, end;
	char *msg;

	start = nsec();
	sleep(1);
	end = nsec();

	if (end <= start)
		ret = 1;

	if (verbose)
		print("nanotime: start %llx, end %llx\n", start, end);
	if(ret){
		msg = smprint("nanotime: FAIL: start %llx end %llx",
			start, end);
		print("%s\n", msg);
		exits(msg);
	}
	print("PASS\n");
	exits("PASS");
}
Beispiel #5
0
static void
periodicThread(void *a)
{
	Periodic *p = a;
	double t, ct, ts;

	vtThreadSetName("periodic");

	ct = nsec()*1e-6;
	t = ct + p->msec;

	for(;;){
		/* skip missed */
		while(t <= ct)
			t += p->msec;

		ts = t - ct;
		if(ts > 1000)
			ts = 1000;
		sleep(ts);
		ct = nsec()*1e-6;
		vtLock(p->lk);
		if(p->die){
			vtUnlock(p->lk);
			break;
		}
		if(t <= ct){
			p->f(p->a);
			t += p->msec;
		}
		vtUnlock(p->lk);
	}
	periodicFree(p);
}
Beispiel #6
0
static void
periodicThread(void *a)
{
	Periodic *p = a;
	vlong t, ct, ts;		/* times in ms. */

	threadsetname("periodic");

	ct = nsec() / 1000000;
	t = ct + p->msec;		/* call p->f at or after this time */

	for(;;){
		ts = t - ct;		/* ms. to next cycle's start */
		if(ts > 1000)
			ts = 1000;	/* bound sleep duration */
		if(ts > 0)
			sleep(ts);	/* wait for cycle's start */

		qlock(&p->lk);
		if(p->die){
			qunlock(&p->lk);
			break;
		}
		ct = nsec() / 1000000;
		if(t <= ct){		/* due to call p->f? */
			p->f(p->a);
			ct = nsec() / 1000000;
			while(t <= ct)	/* advance t to future cycle start */
				t += p->msec;
		}
		qunlock(&p->lk);
	}
	periodicFree(p);
}
Beispiel #7
0
void
main(void)
{
	int64_t start, elapsed, res;
	static Lock l;

	rfork(RFNOTEG|RFREND);
	rStart.l = &rl;
	rCompleted.l = &rl;
	resInWaiter = 0xff;

	spawnWaiter(&l);
	lock(&l);

	alarm(20000);	/* global timeout, FAIL if reached */
	if (!atnotify(failOnTimeout, 1)){
		fprint(2, "%r\n");
		exits("atnotify fails");
	}

	/* verify that lockt returns 0 on timeout */
	start = nsec();
	res = lockt(&l, 1000);
	elapsed = (nsec() - start) / (1000 * 1000);
	if(verbose)
		print("lockt returned %d, elapsed = %d ms\n", res, elapsed);
	if(res != 0 || elapsed < 900 || elapsed > 1300){
		print("FAIL: lockt timeout\n");
		exits("FAIL");
	}

	/* verify that lockt returns 1 if the lock is released and
	 * it can take it
	 */
	resInWaiter = -1;
	qlock(&rl);
	rwakeupall(&rStart);
	qunlock(&rl);
	sleep(1200);
	unlock(&l);

	qlock(&rl);
	while(elapsedInWaiter == 0)
		rsleep(&rCompleted);
	qunlock(&rl);
	if(resInWaiter != 1 || elapsedInWaiter < 1100 || elapsedInWaiter > 1500){
		print("FAIL: lockt delayed acquisition\n");
		exits("FAIL");
	}

	print("PASS\n");
	exits("PASS");
}
Beispiel #8
0
/*
 * May be called with null parent, for root and ctl files.
 * The first call with a null parent is root, all others are ctl
 * files linked at root.
 */
Memblk*
dfcreate(Memblk *parent, char *name, int uid, ulong mode)
{
	Memblk *nf;
	Mfile *m;
	int isctl;

	if(fsfull())
		error("file system full");
	isctl = parent == nil;
	if(parent == nil)
		parent = fs->root;

	if(parent != nil){
		dprint("dfcreate '%s' %M at\n%H\n", name, mode, parent);
		isdir(parent);
		isrwlocked(parent, Wr);
		ismelted(parent);
	}else
		dprint("dfcreate '%s' %M", name, mode);

	if(isctl)
		nf = dballoc(DBctl);
	else
		nf = dballoc(DBfile);
	if(catcherror()){
		mbput(nf);
		if(parent != nil)
			rwunlock(parent, Wr);
		error(nil);
	}

	m = nf->mf;
	nf->d.id = nsec();
	nf->d.mode = mode;
	nf->d.mtime = nf->d.id;
	nf->d.atime = nf->d.id;
	nf->d.length = 0;
	m->uid = usrname(uid);
	nf->d.uid = uid;
	m->gid = m->uid;
	nf->d.gid = nf->d.uid;
	m->muid = m->uid;
	nf->d.muid = nf->d.uid;
	m->name = name;
	nf->d.asize = pmeta(nf->d.embed, Embedsz, nf);
	changed(nf);

	if(parent != nil){
		m->gid = parent->mf->gid;
		nf->d.gid = parent->d.gid;
		dflink(parent, nf);
	}
	noerror();
	dprint("dfcreate-> %H\n within %H\n", nf, parent);
	return nf;
}
Beispiel #9
0
uint taskdelay(uint ms)
{
    uvlong when = 0L;
    uvlong now = 0L;
    Task *t = NULL;
   
    startfdtask();

    now = nsec();
    when = now + (uvlong)ms * 1000000;
    for(t=sleeping.head; t != NULL && t->alarmtime < when; t=t->next)
        ;

    if(t) {
        taskrunning->prev = t->prev;
        taskrunning->next = t;
    } else {
        taskrunning->prev = sleeping.tail;
        taskrunning->next = NULL;
    }
    
    t = taskrunning;
    t->alarmtime = when;

    if(t->prev) {
        t->prev->next = t;
    } else {
        sleeping.head = t;
    }

    if(t->next) {
        t->next->prev = t;
    } else {
        sleeping.tail = t;
    }

    if(!t->system && sleepingcounted++ == 0) {
        taskcount++;
    }

    taskswitch();

    return (nsec() - now) / 1000000;
}
Beispiel #10
0
void
main(int argc, char *argv[])
{
	int i;
	uint64_t start, stop;
	char buf[1];

	(void) close(3);
	start = nsec();
	for(i = 0; i < 1000000000; i++) {
		if (read(3, buf, 1) >= 0){
			fprint(2, "Read of 3 did not fail!\n");
			exits("benchmark broken");
		}
	}
	stop = nsec();
	print("# error benchmark\n");
	print("1000000 %lld\n", stop - start);
}
Beispiel #11
0
uint
taskdelay(uint ms)
{
	uvlong when, now;
	Task *t;
	
	if(!startedfdtask){
		startedfdtask = 1;
        epfd = epoll_create(1);
        assert(epfd >= 0);		
		taskcreate(fdtask, 0, 32768 * 10);
	}

	now = nsec();
	when = now+(uvlong)ms*1000000;
	for(t=sleeping.head; t!=nil && t->alarmtime < when; t=t->next)
		;

	if(t){
		taskrunning->prev = t->prev;
		taskrunning->next = t;
	}else{
		taskrunning->prev = sleeping.tail;
		taskrunning->next = nil;
	}
	
	t = taskrunning;
	t->alarmtime = when;
	if(t->prev)
		t->prev->next = t;
	else
		sleeping.head = t;
	if(t->next)
		t->next->prev = t;
	else
		sleeping.tail = t;

	if(!t->system && sleepingcounted++ == 0)
		taskcount++;
	taskswitch();

	return (nsec() - now)/1000000;
}
Beispiel #12
0
void
main(int argc, char *argv[])
{
	int n;
	Biobuf in;
	char *p;
	char *f[4];

	strcpy(mntpt, "/net");
	cfg.inside = 1;

	ARGBEGIN{
	case 'f':
		dbfile = EARGF(usage());
		break;
	case 'r':
		cfg.resolver = 1;
		break;
	case 'x':
		dbfile = "/lib/ndb/external";
		strcpy(mntpt, "/net.alt");
		break;
	default:
		usage();
	}ARGEND

	now = time(nil);
	nowns = nsec();
	dninit();
	fmtinstall('R', prettyrrfmt);
	if(myipaddr(ipaddr, mntpt) < 0)
		sysfatal("can't read my ip address");
	opendatabase();

	if(cfg.resolver)
		squirrelserveraddrs();

	debug = 1;

	if(argc > 0){
		docmd(argc, argv);
		exits(0);
	}

	Binit(&in, 0, OREAD);
	for(print("> "); p = Brdline(&in, '\n'); print("> ")){
		p[Blinelen(&in)-1] = 0;
		n = tokenize(p, f, 3);
		if(n>=1) {
			dnpurge();		/* flush the cache */
			docmd(n, f);
		}
	}
	exits(0);
}
Beispiel #13
0
void
dfused(Path *p)
{
	Memblk *f;

	f = p->f[p->nf-1];
	isfile(f);
	rwlock(f, Wr);
	f->d.atime = nsec();
	rwunlock(f, Wr);
}
Beispiel #14
0
int
timefmt(Fmt *fmt)
{
	vlong ns;
	Tm tm;
	ns = nsec();
	tm = *localtime(time(0));
	return fmtprint(fmt, "%04d/%02d%02d %02d:%02d:%02d.%03d", 
		tm.year+1900, tm.mon+1, tm.mday, tm.hour, tm.min, tm.sec,
		(int)(ns%1000000000)/1000000);
}
Beispiel #15
0
int
printFirst(void *v, char *s)
{
	/* just not exit, please */
	if(strcmp(s, "alarm") == 0){
		if(verbose)
			fprint(2, "%d: noted: %s at %lld\n", getpid(), s, nsec());
		atnotify(printFirst, 0);
		return 1;
	}
	return 0;
}
Beispiel #16
0
ulong
etimer(ulong key, int n)
{
	if(Stimer != -1)
		drawerror(display, "events: timer started twice");
	Stimer = newkey(key);
	if(n <= 0)
		n = 1000;
	eslave[Stimer].n = n;
	eslave[Stimer].nexttick = nsec()+n*1000000LL;
	return 1<<Stimer;
}
Beispiel #17
0
void
main(int argc, char **argv)
{
	Memimage *x;
	Point c = {208,871};
	int a = 441;
	int b = 441;
	int thick = 0;
	Point sp = {0,0};
	int alpha = 51;
	int phi = 3;
	vlong t0, t1;
	int i, n;
	vlong del;

	if (argc != 2) {
		fprint(2, "usage: arctest number\n");
		exits("usage");
	}
	memimageinit();

	x = allocmemimage(Rect(0,0,1000,1000), CMAP8);
	n = atoi(argv[1]);

	t0 = nsec();
	t0 = nsec();
	t0 = nsec();
	t1 = nsec();
	del = t1-t0;
	t0 = nsec();
	for(i=0; i<n; i++)
		memarc(x, c, a, b, thick, memblack, sp, alpha, phi, SoverD);
	t1 = nsec();
	print("%lld %lld\n", t1-t0-del, del);
}
Beispiel #18
0
static inline void wake_sleepers()
{
    Task *t;
    uvlong now = nsec();

    while((t =sleeping.head) && now >= t->alarmtime){
        deltask(&sleeping, t);

        if(!t->system && --sleepingcounted == 0) taskcount--;

        taskready(t);
    }
}
Beispiel #19
0
int
timefmt(Fmt *fmt)
{
	static char *mon[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", 
		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
	vlong ns;
	Tm tm;
	ns = nsec();
	tm = *localtime(time(0));
	return fmtprint(fmt, "%s %2d %02d:%02d:%02d.%03d", 
		mon[tm.mon], tm.mday, tm.hour, tm.min, tm.sec,
		(int)(ns%1000000000)/1000000);
}
Beispiel #20
0
int fdcheckblock(int fd)
{
	uvlong now,when;
	Task* t;
	now = nsec();


	struct timeval stTime;
	socklen_t len = sizeof(stTime);
	if(getsockopt(fd,SOL_SOCKET,SO_RCVTIMEO,&stTime,&len) == 0){
		when = now + stTime.tv_sec * 1000 * 1000000 + stTime.tv_usec;
		if (when == now){
			return 0;
		}
	}else{
		fprintf(stderr,"getsockopt failed:%s\n",strerror(errno));
		return 0;
	}
	
	for(t=blocking.head; t!=nil && t->alarmtime < when; t=t->next)
		;

	if(t){
		taskrunning->prev = t->prev;
		taskrunning->next = t;
	}else{
		taskrunning->prev = blocking.tail;
		taskrunning->next = nil;
	}
	
	t = taskrunning;
	t->alarmtime = when;
	if(t->prev)
		t->prev->next = t;
	else
		blocking.head = t;
	if(t->next)
		t->next->prev = t;
	else
		blocking.tail = t;

	if(!t->system && blockingcounted++ == 0)
		taskcount++;

	return 1;
}
Beispiel #21
0
void NeatLearner::updatePose(const boost::shared_ptr<::gazebo::msgs::PosesStamped const> &msg)
{
	for (int i = 0; i < msg->pose_size(); ++i) {
		auto poseMsg = msg->pose(i);
		auto name =	poseMsg.name();
		
		if (name == this->modelName_) {
			auto position = poseMsg.position();
			this->position_[0] = position.x();
			this->position_[1] = position.y();
			this->position_[2] = position.z();
		}
	}
	auto timeStamp = msg->time();
	double seconds = (double)timeStamp.sec();
	double nanoseconds = (double)timeStamp.nsec() / 1000000000.0;
	this->currentTime_ = seconds + nanoseconds;

}
Beispiel #22
0
struct api_thread *
api_add_thread(struct gspos pos, struct api_thread_table *api_thread_table, void *main_thread_data, struct api_prim_table *api_prim_table, gsvalue entry)
{
    int i;
    struct api_thread *thread;

    api_take_thread_queue();

    thread = 0;
    for (i = 0; i < API_NUMTHREADS; i++) {
        api_take_thread(&api_thread_queue->threads[i]);
        if (api_thread_queue->threads[i].state == api_thread_st_unused) {
            thread = &api_thread_queue->threads[i];
            api_thread_queue->numthreads++;
            goto have_thread;
        } else {
            api_release_thread(&api_thread_queue->threads[i]);
        }
    }
    gsfatal(UNIMPL("thread queue overflow"));

have_thread:
    api_release_thread_queue();

    if (gsflag_stat_collection) {
        thread->start_time = nsec();
        thread->prog_term_time = 0;
    }
    thread->state = api_thread_st_active;
    thread->ismain = 0;

    thread->api_thread_table = api_thread_table;
    thread->api_prim_table = api_prim_table;
    thread->client_data = main_thread_data;
    thread->status = 0;

    thread->code = api_alloc_code_segment(pos, thread, entry);
    thread->eprim_blocking = 0;

    return thread;
}
Beispiel #23
0
/*
 * Report that a file has been modified.
 * Modification times propagate up to the root of the file tree.
 * But frozen files are never changed.
 */
void
dfchanged(Path *p, int muid)
{
	Memblk *f;
	u64int t, u;
	int i;

	t = nsec();
	u = muid;
	for(i = 0; i < p->nf; i++){
		f = p->f[i];
		rwlock(f, Wr);
		if(f->frozen == 0)
			if(!catcherror()){
				f->d.mtime = t;
				f->d.atime = t;
				f->d.muid = muid;
				changed(f);
				noerror();
			}
		rwunlock(f, Wr);
	}
}
Beispiel #24
0
void 
yurexread(Req *r)
{
	int qid = (int)r->fid->qid.path;
	char data[32];
	vlong tnsec;

	switch(qid){
	case Qbbu:
		seprint(data, data+sizeof(data), "%ld\n", yc.curval);
		readstr(r, data);
		break;
	case Qmbbups:
		tnsec = nsec();
		if(tnsec == yc.oldnsec) tnsec++;
		seprint(data, data+sizeof(data), "%lld\n", (yc.curval-yc.oldval)*1000*10000/((tnsec-yc.oldnsec)/100000));
		readstr(r, data);
		yc.oldval = yc.curval;
		yc.oldnsec = tnsec;
	}

	respond(r, nil);
}
Beispiel #25
0
static inline int next_task_sleeptime(int min)
{
    Task *t;
    uvlong now = 0;
    int ms = 0;

    if((t=sleeping.head) == NULL)
        ms = -1;
    else{
        now = nsec();
        if(now >= t->alarmtime) {
            ms = 0;
        } else {
            ms = (t->alarmtime - now) / 1000000;
        }

        if(ms % min != 0) ms = ms - (ms % min);
    }

    if(ms == 0) ms = min;

    return ms;
}
Beispiel #26
0
static void
X917(uint8_t *rand, int nrand)
{
	int i, m, n8;
	uint64_t I, x;

	/* 1. Compute intermediate value I = Ek(time). */
	I = nsec();
	triple_block_cipher(x917state.des3.expanded, (uint8_t*)&I, 0); /* two-key EDE */

	/* 2. x[i] = Ek(I^seed);  seed = Ek(x[i]^I); */
	m = (nrand+7)/8;
	for(i=0; i<m; i++){
		x = I ^ x917state.seed;
		triple_block_cipher(x917state.des3.expanded, (uint8_t*)&x, 0);
		n8 = (nrand>8) ? 8 : nrand;
		memcpy(rand, (uint8_t*)&x, n8);
		rand += 8;
		nrand -= 8;
		x ^= I;
		triple_block_cipher(x917state.des3.expanded, (uint8_t*)&x, 0);
		x917state.seed = x;
	}
}
Beispiel #27
0
static void
yurexwork(void *)
{
	char buf[8];
	ulong val;
	int yfd;
	int c;

	yfd = yc.ep->dfd;
	yc.issueing_cmd = YCMD_NONE;
	yc.accepted_cmd = YCMD_NONE;

	print("YUREX: maxpkt = %d dfd = %d\n", yc.ep->maxpkt, yfd);

	//set mode
	memset(buf, YCMD_PADDING, sizeof(buf));
	buf[0] = YCMD_MODE;
	buf[1] = 0;
	buf[2] = YCMD_EOF;
	write(yfd, buf, sizeof(buf));
	sleep(500);

	//read value request
	memset(buf, YCMD_PADDING, sizeof(buf));
	buf[0] = YCMD_READ;
	buf[1] = YCMD_EOF;
	yc.issueing_cmd = YCMD_READ;
	yc.accepted_cmd = YCMD_NONE;
	write(yfd, buf, sizeof(buf));
	sleep(500);

	for(;;){
		if(yc.ep == nil) sysfatal(nil);
		memset(buf, YCMD_PADDING, sizeof(buf));
		c = read(yfd, buf, sizeof(buf));
		if(c <= 0) sysfatal("%r");
		switch(buf[0]){
		case YCMD_ACK:
			if(buf[1] == yc.issueing_cmd){
				fprint(2, "YUREX DEBUG: ack cmd 0x%.2x\n", buf[1]);
				yc.accepted_cmd = buf[1];
			}else{
				fprint(2, "YUREX DEBUG: cmd-ack mismatch: recvd:0x%.2x expect 0x%.02x\n",
					buf[1], yc.issueing_cmd);
				yc.issueing_cmd = YCMD_NONE;
				yc.accepted_cmd = YCMD_NONE;
			}
			break;
		case YCMD_READ:
		case YCMD_VALUE:
			val = (buf[2]<<24) + (buf[3]<<16) + (buf[4]<<8) + buf[5];
			if(yc.initialized == 0){
				yc.oldval = val;
				yc.oldnsec = nsec();
				yc.initialized = 1;
			}
			yc.curval = val;
			//fprint(2, "YUREX DEBUG: BBU %ld\n", val);
			break;
		default:
			fprint(2, "YUREX DEBUG: unknown message: 0x%.2x\n", buf[0]);
		}
	}
}
Beispiel #28
0
uint
msec(void)
{
	return nsec()/1000000;
}
Beispiel #29
0
void
fdtask(void *v)
{
	int i, ms;
	Task *t;
	uvlong now;
	
	tasksystem();
	taskname("fdtask");
	for(;;){
		//fprintf(stderr,"pooling0\n");
		/* let everyone else run */
	   taskyield();
		//fprintf(stderr,"\n after yield %d\n", maysamYieldRet);
		//while(taskyield() > 0);
		/* we're the only one runnable - poll for i/o */
		errno = 0;
		taskstate("poll");
		//Added by Maysam Yabandeh
		//taskname("fdtask(%d)",npollfd);
		if((t=sleeping.head) == nil)
			ms = -1;
		else{
			/* sleep at most 5s */
			now = nsec();
			if(now >= t->alarmtime)
				ms = 0;
			else if(now+5*1000*1000*1000LL >= t->alarmtime)
				ms = (t->alarmtime - now)/1000000;
			else
				ms = 5000;
		}
		//Added by Maysam Yabandeh
		//if (ms == -1 && maysamYieldRet == 0) ms = 0;
		if (ms == -1) ms = 0;
		//fprintf(stderr,"pooling ms is %d npollfd is %d\n", ms, npollfd);
#ifndef USE_SHM
		if(poll(pollfd, npollfd, ms) < 0){
		//fprintf(stderr,"pooling error\n");
			if(errno == EINTR)
				continue;
			fprint(2, "poll: %s\n", strerror(errno));
			taskexitall(0);
		}

		//fprintf(stderr,"pooling2\n");
		/* wake up the guys who deserve it */
		for(i=0; i<npollfd; i++){
			while(i < npollfd && pollfd[i].revents){
		//fprintf(stderr,"pooling3\n");
				taskready(polltask[i]);
				--npollfd;
				pollfd[i] = pollfd[npollfd];
				polltask[i] = polltask[npollfd];
			}
		}
#else
		/* wake up the guys who deserve it */
		//extern mpass::MessageEndPoint msg_end_point;
		mpass::MessageEndPoint *end_point = &mpass::msg_end_point;
		for(i=0; i<npollfd; i++){
		   int &fd = pollfd[i].fd;
			bool read = pollfd[i].events & POLLIN;
			mpass::Connection *conn = &end_point->conn_array[fd];
			if ( (read && !conn->rcv_q->is_empty()) || (!read && !conn->snd_q->is_full()) )
			{
				taskready(polltask[i]);
				--npollfd;
				pollfd[i] = pollfd[npollfd];
				polltask[i] = polltask[npollfd];
			}
		}
#endif
		
		//fprintf(stderr,"pooling4\n");
		now = nsec();
		while((t=sleeping.head) && now >= t->alarmtime){
		//fprintf(stderr,"pooling5\n");
			deltask(&sleeping, t);
			if(!t->system && --sleepingcounted == 0)
				taskcount--;
			taskready(t);
		}
	}
}
Beispiel #30
0
SmbProcessResult
smbnegotiate(SmbSession *s, SmbHeader *h, uchar *, SmbBuffer *b)
{
	ushort index;
	int i;
	uchar bufferformat;

	if (!smbcheckwordcount("negotiate", h, 0))
		return SmbProcessResultFormat;
	if (s->state != SmbSessionNeedNegotiate) {
		/* this acts as a complete session reset */
		smblogprint(-1, "smbnegotiate: called when already negotiated\n");
		return SmbProcessResultUnimp;
	}
	i = 0;
	index = 0xffff;
	while (smbbuffergetb(b, &bufferformat)) {
		char *s;
		if (bufferformat != 0x02) {
			smblogprint(-1, "smbnegotiate: unrecognised buffer format 0x%.2ux\n", bufferformat);
			return SmbProcessResultFormat;
		}
		if (!smbbuffergetstr(b, 0, &s)) {
			smblogprint(-1, "smbnegotiate: no null found\n");
			return SmbProcessResultFormat;
		}
		smblogprint(h->command, "smbnegotiate: '%s'\n", s);
		if (index == 0xffff && strcmp(s, "NT LM 0.12") == 0)
			index = i;
		i++;
		free(s);
	}
	if (index != 0xffff) {
		Tm *tm;
		ulong capabilities;
		ulong bytecountfixupoffset;

		h->wordcount = 17;
		if (!smbbufferputheader(s->response, h, nil)
			|| !smbbufferputs(s->response, index)
			|| !smbbufferputb(s->response, 3)			/* user security, encrypted */
			|| !smbbufferputs(s->response, 1)			/* max mux */
			|| !smbbufferputs(s->response, 1)			/* max vc */
			|| !smbbufferputl(s->response, smbglobals.maxreceive)		/* max buffer size */
			|| !smbbufferputl(s->response, 0x10000)		/* max raw */
			|| !smbbufferputl(s->response, threadid()))	/* session key */
			goto die;
		/* <= Win2k insist upon this being set to ensure that they observe the prototol (!) */
		capabilities = CAP_NT_SMBS;
		if (smbglobals.unicode)
			capabilities |= CAP_UNICODE;
		tm = localtime(time(nil));
		s->tzoff = tm->tzoff;
		if (!smbbufferputl(s->response, capabilities)
			|| !smbbufferputv(s->response, nsec() / 100 + (vlong)10000000 * 11644473600LL)
			|| !smbbufferputs(s->response, -s->tzoff / 60)
			|| !smbbufferputb(s->response, 8))	/* crypt len */
			goto die;
		bytecountfixupoffset = smbbufferwriteoffset(s->response);
		if (!smbbufferputs(s->response, 0))
			goto die;
		s->cs = auth_challenge("proto=mschap role=server");
		if (s->cs == nil) {
			smblogprint(h->command, "smbnegotiate: couldn't get mschap challenge\n");
			return SmbProcessResultMisc;
		}
		if (s->cs->nchal != 8) {
			smblogprint(h->command, "smbnegotiate: nchal %d\n", s->cs->nchal);
			return SmbProcessResultMisc;
		}
		if (!smbbufferputbytes(s->response, s->cs->chal, s->cs->nchal)
			|| !smbbufferputstring(s->response, nil, SMB_STRING_UNICODE, smbglobals.primarydomain)
			|| !smbbufferfixuprelatives(s->response, bytecountfixupoffset))
			goto die;
	}
	else {
		h->wordcount = 1;
		if (!smbbufferputheader(s->response, h, nil)
			|| !smbbufferputs(s->response, index)
			|| !smbbufferputs(s->response, 0))
			goto die;
	}
	s->state = SmbSessionNeedSetup;
	return SmbProcessResultReply;
die:
	return SmbProcessResultDie;
}