Пример #1
0
//==============================================================================
// EnumHosts()
//
// Enumerates sessions running on the given IP address.
//==============================================================================
void CDarkPeer::EnumHosts(const char* serverIP, const char* password)
{
#if (GAME == GAME_THIEF || GAME == GAME_DROMED)
	if (!g_ConnectAttempt.IsActive())
		return dbgassert(false && "no connect attempt?");
#endif

	dbgassert(m_pHostAddress);

	HRESULT hRes;
	DPN_APPLICATION_DESC dpnAppDesc;
	wchar_t wcBuff[150];

	AnsiToWide(wcBuff, serverIP, sizeof(wcBuff));

	ZeroMemory(&dpnAppDesc, sizeof(DPN_APPLICATION_DESC));
	dpnAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
	dpnAppDesc.guidApplication = GAME_GUID;

	hRes = m_pHostAddress->AddComponent(DPNA_KEY_HOSTNAME, wcBuff, (DWORD)(wcslen(wcBuff)+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING);

	int port = g_ConnectAttempt.GetPort();
	hRes = m_pHostAddress->AddComponent(DPNA_KEY_PORT, &port, sizeof(port), DPNA_DATATYPE_DWORD);

	hRes = m_pDP->EnumHosts(&dpnAppDesc, m_pHostAddress, m_pDeviceAddress, NULL, 0, INFINITE, 0, 
		INFINITE, NULL, &m_enumSessionAsyncOp, NULL);
	if (FAILED(hRes))
		ConPrintF("Failed to enumerate hosts (%x).", hRes);
}
Пример #2
0
Operator::GetNextResultT BitEntropyPrinter::getNext(unsigned short threadid)
{
	Page* in;
	Operator::ResultCode rc;
	unsigned int tupoffset;

	Page* out = output[threadid];
	out->clear();

	// Populate output.
	//
	populateOutputPage(out, schema, threadid);

	// Do first read.
	//
	Operator::GetNextResultT result = nextOp->getNext(threadid);
	rc = result.first;
	in = result.second;
	tupoffset = 0;

	while (rc != Error) 
	{
		void* tuple;

		dbgassert(rc != Error);
		dbgassert(in != NULL);
		dbgassert(tupoffset >= 0);
		dbgassert(tupoffset <= (buffsize / nextOp->getOutSchema().getTupleSize()) + 1);

		while ( (tuple = in->getTupleOffset(tupoffset++)) ) 
		{
			// Calculate entropy.
			//
			CtLong val = *(CtLong*)(nextOp->getOutSchema().calcOffset(tuple, fieldno));
			addStatsToPage(out, schema, val);
		}

		// If input source depleted, remove state information and return.
		//
		if (rc == Finished) 
		{
			return make_pair(Finished, out);
		}

		// Read more input.
		//
		Operator::GetNextResultT result = nextOp->getNext(threadid);
		rc = result.first;
		in = result.second;
		tupoffset = 0;
	}

	state[threadid] = State(NullPage, Error, 0);
	return make_pair(Error, NullPage);	// Reached on Error
}
Пример #3
0
Файл: cpu.c Проект: glguida/mh
int cpu_number_from_lapic(void)
{
	unsigned physid, id;
	extern int cpu_phys_to_id[UKERN_MAX_PHYSCPUS];

	physid = lapic_getcurrent();
	dbgassert(physid < UKERN_MAX_PHYSCPUS);
	id = cpu_phys_to_id[physid];
	dbgassert(id < UKERN_MAX_CPUS);
	return id;
}
Пример #4
0
void CGamesysManager::SetNetCategoryByName(const char* objName, eNetworkCategory cat)
{
	int obj = g_pObjSys->GetObjectNamed(objName);
	dbgassert(obj);

	if (obj)
		_SetNetworkCategory(obj, cat);
}
Пример #5
0
void* HashTable::allocate(unsigned int offset, void* allocsource)
{
	BucketHeader* bhlast = NULL;

	for (BucketHeader* bh = getBucketHeader(offset)
			; bh != NULL
			; bh = bh->nextBucket)
	{
		dbgassertinitialized(bh);
		dbg2assert(bh->used <= bucksize);
		if (bh->used + tuplesize <= bucksize) 
		{
			// Fast path: it fits!
			//
			void* freeloc = ((char*)bh) + sizeof(BucketHeader) + bh->used;
			bh->used += tuplesize;
			return freeloc;
		}

		bhlast = bh;
	}

	// Overflow. Allocate new page and chain after current bucket.
	// Allocations because of overflow always allocate NUMA-local memory.
	//
	dbgassert(bhlast != NULL);
	dbgassert(bhlast->nextBucket == NULL);
	dbgassert(tuplesize <= bucksize);

	atomic_increment(&spills);
	
	void* newbuck = NULL;
	newbuck = numaallocate_local("HTbO", sizeof(BucketHeader) + bucksize, allocsource);
	assert(newbuck != NULL);

	BucketHeader* bhnew = (BucketHeader*) newbuck;
	bhnew->clear();
	bhnew->used += tuplesize;

	bhlast->nextBucket = bhnew;

	void* freeloc = ((char*)newbuck) + sizeof(BucketHeader);
	return freeloc;
}
Пример #6
0
Operator::GetNextResultT IntGeneratorOp::getNext(unsigned short threadid)
{
	dbgassert(output.at(threadid) != NULL);
	Page* out = output[threadid];
	out->clear();

	while (out->canStoreTuple())
	{
		void* tuple = produceOne(threadid);
		if (tuple == NULL)
			return make_pair(Finished, out);

		void* target = out->allocateTuple();
		dbgassert(target != NULL);

		schema.copyTuple(target, tuple);
	}

	return make_pair(Ready, out);
}
Пример #7
0
void IntGeneratorOp::threadInit(unsigned short threadid)
{
	static const char* dummy = "The Past performance does not guarantee future results. We provide self-directed users with data services, and do not make recommendations or offer legal or other advice. You alone are responsible for evaluating the merits and risks associated with the use of our systems, services or products.";

	scratchspace.at(threadid) = new char[schema.getTupleSize()];
	dbgassert(scratchspace.at(threadid) != NULL);
	schema.copyTuple(scratchspace.at(threadid), dummy);

	output.at(threadid) = new Page(buffsize, schema.getTupleSize(), this);
	producedsofar.at(threadid) = 0;
}
Пример #8
0
void addStatsToPage(Operator::Page* dest, Schema& schema, CtLong val)
{
	for (unsigned int i=0; i<sizeof(CtLong)*8; ++i)
	{
		void* desttup = dest->getTupleOffset(i);
		dbgassert(desttup != NULL);
		int offset = 2 + ((val >> i) & 0x1uLL);
		CtLong oldval = schema.asLong(desttup, offset);
		oldval += 1;
		schema.writeData(desttup, offset, &oldval);
	}
}
Пример #9
0
void CGamesysManager::CreateDerivedAvatars()
{
	// Create new archetypes derived from MP Avatar with differing models
	int newAvatar = CreateNewArchetype(Arch.MPAvatar, "MP Avatar 2");
	dbgassert(newAvatar && "failed to create avatar 2");

	_ObjSetModelName(newAvatar, "ThiefM02"); // ThiefMale

	newAvatar = CreateNewArchetype(Arch.MPAvatar, "MP Avatar 3");
	dbgassert(newAvatar && "failed to create avatar 3");

	_ObjSetModelName(newAvatar, "keeper01"); // KeeperAgent

	newAvatar = CreateNewArchetype(Arch.MPAvatar, "MP Avatar 4");
	dbgassert(newAvatar && "failed to create avatar 4");

	_ObjSetModelName(newAvatar, "malsev01"); // MaleServ1

	newAvatar = CreateNewArchetype(Arch.MPAvatar, "MP Avatar 5");
	dbgassert(newAvatar && "failed to create avatar 5");

	_ObjSetModelName(newAvatar, "basso"); // Basso
}
Пример #10
0
int CGamesysManager::SetObjectName(int object, const char* name)
{
	dbgassert(object);

	if (object)
	{
		return g_pMultiNameProp->Set(object, name);
	}
	else
	{
		DbgPrint("%s: no object specified for name %s.", __FUNCTION__, name);
		return 0;
	}
}
Пример #11
0
Operator::GetNextResultT ConsumeOp::getNext(unsigned short threadid)
{
	CtInt val = 0;
	dbgassert(vec.at(threadid) != NULL);
	Page* out = vec[threadid];
	GetNextResultT result;

	assertaddresslocal(&val);

	const int tupw = nextOp->getOutSchema().getTupleSize();

	do {
		result = nextOp->getNext(threadid);
		dbgassert(result.first != Error);

		Page* in = result.second;
		Page::Iterator it = in->createIterator();

		void* tuple;
		while ( (tuple = it.next()) ) 
		{
			CtInt* casttuple = (CtInt*) tuple;
			for (int i=0; i<(tupw/4); ++i)
			{
				val ^= casttuple[i];
			}
		}
	} while(result.first == Operator::Ready);

	assertaddresslocal(&val);

	void* dest = out->allocateTuple();
	schema.writeData(dest, 0, &val);

	return make_pair(Finished, out);
}
Пример #12
0
void* IntGeneratorOp::produceOne(unsigned short threadid)
{
	dbgassert(scratchspace.at(threadid) != NULL);
	void* tuple = scratchspace[threadid];

	CtLong* curval = &producedsofar[threadid];

	if (*curval >= totaltuples)
		return NULL;

	++(*curval);
	schema.writeData(tuple, 0, curval);

	return tuple;
}
Пример #13
0
//======================================================================================
// Purpose: Closes connections in the event of a crash.
//======================================================================================
void CDarkPeer::CrashCleanup()
{
	dbgassert(g_pDarkNet);

	if (m_gsc)
	{
		//m_gsc->SendQuitting(IGSClient::ExitReason_AppCrash);
		GS_DestroyClient(m_gsc);
	}

	Close();

	// Shut down the DirectPlay 4 wrapper. Will also cause "this" to be deleted.
	WrapperTerm();
}
Пример #14
0
void BitEntropyPrinter::init(libconfig::Config& root, libconfig::Setting& node)
{
	MapWrapper::init(root, node);

	fieldno = (int) node["field"];

	ostringstream ss;
	ss << "Prints times bit is 0 or 1 for the first 64 bits of fieldno=" 
		<< fieldno + 1 << ".";
	description = ss.str();

	// Assert if output doesn't fit at least one record for each bit.
	//
	dbgassert(schema.getTupleSize() * sizeof(CtLong) * 8 >= buffsize);
}
Пример #15
0
void populateOutputPage(Operator::Page* dest, Schema& schema, unsigned short threadid)
{
	CtInt cttid = threadid;
	CtLong ctzero = 0;

	for (unsigned int i=0; i<sizeof(CtLong)*8; ++i)
	{
		CtInt ctbit = i;
		void* desttup = dest->allocateTuple();
		dbgassert(desttup != NULL);

		schema.writeData(desttup, 0, &cttid);
		schema.writeData(desttup, 1, &ctbit);
		schema.writeData(desttup, 2, &ctzero);
		schema.writeData(desttup, 3, &ctzero);
	}
}
Пример #16
0
void cAnsiStr::Assign(int dataLength, const char* str)
{
	if (!dataLength)
		return dbgassert(false && "Invalid length");

	if (dataLength == 0)
	{
		if (m_pString != NULL)
		{
			m_pString[0] = '\0';
			m_dataLength = 0;
		}
		return;
	}
	if (str && str != m_pString)
	{
		cAnsiStrFns::AllocBuffer(this, NULL, dataLength);
		memcpy(m_pString, str, dataLength);
		m_pString[dataLength] = '\0';
		m_dataLength = dataLength;
	}


	//	if (str || m_pString)
	//	{
	//		if (dataLength > m_allocLength)
	//			cAnsiStrFns::AllocBuffer(this, NULL, dataLength);
	//		if (m_pString && str)
	//		{
	//			memcpy(m_pString, str, dataLength);
	//			m_dataLength = dataLength;

	//			m_pString[dataLength] = NULL;
	//		}
	//		else if (!dataLength)
	//			dbgassert(false && "Null string assignment");
	//	}
}
Пример #17
0
void dbgassertinitialized(void* bh)
{
	dbgassert(*(unsigned long long*)bh != 0xBCBCBCBCBCBCBCBCuLL);
}
Пример #18
0
Operator::ResultCode IndexHashJoinOp::scanStart(unsigned short threadid,
		Page* thrudatapage, Schema& thrudataschema)
{
	dbgassert(threadid < threadgroups.size());
	const unsigned short groupno = threadgroups[threadid];
	dbgassert(groupno < barriers.size());

	TRACE('1');

	// Build hash table.
	//
	GetNextResultT result;
	result.first = Operator::Ready;
	ResultCode rescode;

	rescode = buildOp->scanStart(threadid, thrudatapage, thrudataschema);
	if (rescode == Operator::Error) {
		return Error;
	}

	Schema& buildschema = buildOp->getOutSchema();
	while (result.first == Operator::Ready) 
	{
		result = buildOp->getNext(threadid);

		if (result.first == Operator::Error)
			return Error;

		Page* page = result.second;
		void* tup = NULL;
		unsigned int hashbucket;

		Page::Iterator it = page->createIterator();
		while( (tup = it.next()) ) 
		{
			// Find destination bucket.
			hashbucket = buildhasher.hash(tup);
			void* joinkey = buildschema.calcOffset(tup, joinattr1);

			// Copy key to idxdata page.
			void* idxdatatup = idxdatapage[threadid]->allocateTuple();
			assert(idxdatatup != NULL);
			idxdataschema.writeData(idxdatatup, 0, joinkey);

			// Project on build, copy result to target.
			void* target = hashtable[groupno].atomicAllocate(hashbucket, this);
			sbuild.writeData(target, 0, joinkey);
			for (unsigned int j=0, buildattrtarget=0; j<projection.size(); ++j) 
			{
				if (projection[j].first != BuildSide)
					continue; 

				unsigned int attr = projection[j].second;
				sbuild.writeData(target, buildattrtarget+1,	// dest, col in output
						buildschema.calcOffset(tup, attr));	// src 
				buildattrtarget++;
			}
		}
	}

	if (result.first == Operator::Error) {
		return Error;
	}

	rescode = buildOp->scanStop(threadid);
	if (rescode == Operator::Error) {
		return Error;
	}

	TRACE('2');

	// This thread is complete. Wait for other threads in the same group (ie.
	// partition) before you continue, or this thread might lose data.
	//
	barriers[groupno].Arrive();

	TRACE('3');

	// Hash table is complete now, every thread can proceed.
	// Handle first call: 
	// 0. Start scan on probe.
	// 1. Make state.location point at first output tuple of probeOp->GetNext.
	// 2. Place htiter and pgiter.
	
	rescode = probeOp->scanStart(threadid, idxdatapage[threadid], idxdataschema);
	if (rescode == Operator::Error) {
		return Error;
	}

	void* tup2;
	tup2 = readNextTupleFromProbe(threadid);
	hashjoinstate[threadid]->location = tup2;

	if (tup2 != NULL) {
		unsigned int bucket = probehasher.hash(tup2);
		hashtable[groupno].placeIterator(hashjoinstate[threadid]->htiter, bucket);
	} else {
		// Probe is empty?!
		rescode = Finished;
	}

	TRACE('4');

	return rescode;
}