void LinuxNetworkEventListener::workerProc() {

	while (!Thread::canFinish()) {
		try {
			PollBase::Result res;
			PollBase::WaitStatus wt = fdSelect.wait(nil, res);

			if (wt == PollBase::waitWakeUp) {
				while (pumpMessage());
			} else {

				AutoArray<std::pair<ISleepingObject *, natural>,SmallAlloc<32> > tocall;

				SysTime tm  = SysTime::now();
				FdData *listeners = reinterpret_cast<FdData *>(res.userData);
				for (ListenerMap::Iterator iter = listeners->listeners.getFwIter(); iter.hasItems();) {
					const FdListener &l = iter.peek();
					if (res.flags & l.waitMask) {
						tocall.add(std::make_pair(l.notify,res.flags & l.waitMask));
						listeners->listeners.erase(iter);
//						l.notify->wakeUp(con.waitMask & l.waitMask);
					} else if (l.waitTimeout.expired(tm)) {
						tocall.add(std::make_pair(l.notify,0));
						listeners->listeners.erase(iter);
	//					l.notify->wakeUp(0);
					} else {
						iter.skip();
					}
				}
				updateFdData(listeners,res.fd);

				for (natural i = 0; i < tocall.length(); i++) {
					tocall[i].first->wakeUp(tocall[i].second);
				}
			}
		} catch (const Exception &e) {
			AppBase::current().onThreadException(e);
		} catch (const std::exception &e) {
			AppBase::current().onThreadException(StdException(THISLOCATION,e));
		} catch (...) {
			AppBase::current().onThreadException(UnknownException(THISLOCATION));
		}
	}

	fdSelect.cancelAll(CleanUpProc(this));
/*	fdSelect.dropAll();
	while (fdSelect.hasItems()) {
		const LinuxFdSelect::FdInfo &con = fdSelect.getNext();
		FdData *listeners = reinterpret_cast<FdData *>(con.data);
		if (listeners) delete listeners;
		fdSelect.unset(con.fd);
	}
	*/

}
Beispiel #2
0
ConstValue LocalView::runReduce(const ConstValue &rows) const {

	AutoArray<KeyAndDocId, SmallAlloc<256> > keylist;
	AutoArray<ConstValue, SmallAlloc<256> > values;
	keylist.reserve(rows.length());
	values.reserve(rows.length());
	for (JSON::ConstIterator iter = rows->getFwConstIter(); iter.hasItems();) {
		const JSON::ConstValue &v = iter.getNext();
		keylist.add(KeyAndDocId(v["key"],v["id"].getStringA()));
		values.add(v["value"]);
	}
	return reduce(keylist,values,false);

}
Beispiel #3
0
static void couchLoadData(PrintTextA &print) {
	CouchDB db(getTestCouch());
	db.use(DATABASENAME);


	AutoArray<Document, SmallAlloc<50> > savedDocs;

	Changeset chset(db.createChangeset());
	natural id=10000;
	JSON::Value data = db.json.factory->fromString(strdata);
	for (JSON::Iterator iter = data->getFwIter(); iter.hasItems();) {
		const JSON::KeyValue &kv= iter.getNext();
		Document doc;
		doc.edit(db.json)
				("name",kv[0])
				("age",kv[1])
				("height",kv[2])
				("_id",ToString<natural>(id,16));
		id+=14823;
		savedDocs.add(doc);
		chset.update(doc);
	}
	chset.commit(false);
	Set<StringA> uuidmap;

	for (natural i = 0; i < savedDocs.length(); i++) {
		StringA uuid = savedDocs[i]["_id"]->getStringUtf8();
//		print("%1\n") << uuid;
		uuidmap.insert(uuid);
	}
	print("%1") << uuidmap.size();

}
Beispiel #4
0
LightSpeed::StringA dbOrderFromJSON(const LightSpeed::JSON::INode &nd) {
	using namespace LightSpeed;
	AutoArray<char, SmallAlloc<256> > buff;
	for (natural i = 0; i < nd.getEntryCount();i++) {
		ConstStrA fld = nd[i].getStringUtf8();
		if (fld.empty() || fld == ConstStrA('^') || fld.find('`') != naturalNull)
			  throw ErrorMessageException(THISLOCATION, "Unacceptable field name");
		if (i) buff.append(ConstStrA(", "));
		if (fld[0] == '^') {
			buff.add('`');buff.append(fld.offset(1));buff.add('`');
			buff.append(ConstStrA(" DESC"));
		} else {
			buff.add('`');buff.append(fld);buff.add('`');
			buff.append(ConstStrA(" ASC"));
		}
	}
	return ConstStrA(buff);
}
Beispiel #5
0
int LightSpeed::AppBase::main_entry( int argc, wchar_t *argv[], ConstStrW pathname)
{
	AutoArray<ConstStrW> params;
	params.reserve(argc);
	for (int i = 0; i < argc; i++)
		params.add(ConstStrW(argv[i]));		
	appPathname = pathname;
	return startApp(Args(params));
}
Beispiel #6
0
int LightSpeed::AppBase::main_entry( int argc, char *argv[], ConstStrW pathname)
{
	AutoArray<String> params;
	AutoArray<ConstStrW> wparams;
	params.reserve(argc);
	for (int i = 0; i < argc; i++)
		params.add(String(argv[i]));

	wparams.append(params);
	appPathname = pathname;
	return startApp(Args(wparams));
}
Beispiel #7
0
	bool ServiceApp::processRequest(const void *request)
	{
		const char *p = reinterpret_cast<const char*>(request);
		natural count = *p++;
		ConstStrA command(p);
		p += command.length() + 1;
		AutoArray<String,StaticAlloc<256> > params;
		AutoArray<ConstStrW,StaticAlloc<256> > wparams;
		for(natural i = 0;i < count;i++){
			ConstStrA param(p);
			p += param.length() + 1;
			params.add(String(param));
			wparams.add(ConstStrW(params[i]));
		}
		AutoArray<byte> output;
		output.resize(instance->getReplyMaxSize());
		SeqOutputBuffer fakeout(output.data() + sizeof (integer), output.length() - sizeof (integer));
		fakeout.setStaticObj();
		integer res = -1;
		bool stop = false;
		SeqFileOutput out(&fakeout);
		try {
			res = onMessage(command, wparams, out);
			stop = command == ConstStrA(stopCmd);
		}
		catch(std::exception & e){
			TextOut<SeqFileOutput> msg(out);
			msg("%1") << e.what();
			res = -1;
		}
		try {
			*reinterpret_cast<integer*>(output.data()) = res;
			instance->sendReply(output.data(), fakeout.length() + sizeof (integer));
		}
		catch(...){
		}
		return !stop;
	}