Beispiel #1
0
	// CF-03: Resize data (J)
	void SetElementSize (unsigned int J)
	{
		op_assert (J);
		const unsigned int OldSize = GetSize();
		ElementSize_ = J;
		Resize (OldSize);
	 }
ArrayNegativeIndex<T>::ArrayNegativeIndex(int startIndex, int endIndex)
:m_startIndex(startIndex), m_endIndex(endIndex)
{
	op_assert(endIndex >= startIndex);
	int dataSize = endIndex - startIndex;
	m_data.resize(dataSize+1, 0);
}
Beispiel #3
0
/* ------- Miscellaneous Menu Commands -------------- */
void set_menu_enabled(
	short menu_id,
	short item,
	NMBoolean enabled)
{
#if defined(OP_PLATFORM_MAC_CFM) || defined(OP_PLATFORM_MAC_MACHO)
	MenuHandle menu= GetMenuHandle(menu_id);

#ifndef OP_PLATFORM_MAC_CARBON_FLAG
	if (enabled)
	{
		EnableItem(menu, item);
	} else {
		DisableItem(menu, item);
	}
#else
	if (enabled) {
		EnableMenuItem(menu, item);
	} else {
		DisableMenuItem(menu, item);
	}
#endif // OP_PLATFORM_MAC_CARBON_FLAG

#elif defined(OP_PLATFORM_WINDOWS)
	HMENU menu= GetMenu(screen_window);

	op_assert(menu);
	EnableMenuItem(menu, MAKE_MENU_COMMAND(menu_id, item), 
		enabled ? MF_ENABLED : MF_GRAYED);
#endif

	return;
}
Beispiel #4
0
void
OTIPEndpoint::MakeEnumerationResponse(void)
{
	DEBUG_ENTRY_EXIT("OTIPEndpoint::MakeEnumerationResponse");

	mEnumerationResponseLen = sizeof(IPEnumerationResponsePacket) + mConfig.customEnumDataLen;

	//	in case we created one from a previous listen...
	if (mEnumerationResponseData)
		delete[] mEnumerationResponseData;
		
	mEnumerationResponseData = (NMUInt8 *)new char[mEnumerationResponseLen];

	IPEnumerationResponsePacket *theResponse = (IPEnumerationResponsePacket *) mEnumerationResponseData;
	InetInterfaceInfo info;
	NMErr		status;
	TNetbuf			addr;
	NMSInt16		len;
	
	addr = mStreamEndpoint->mLocalAddress;
	status = OTInetGetInterfaceInfo(&info, kDefaultInetInterface);
	if (status == kNMNoError)
		((InetAddress *)addr.buf)->fHost = info.fAddress;
	
	len = build_ip_enumeration_response_packet((char *) theResponse, mConfig.gameID, kVersion,
			info.fAddress, ((InetAddress *)addr.buf)->fPort, mConfig.name, mConfig.customEnumDataLen,
			mConfig.customEnumData);
			
	op_assert(len <= mEnumerationResponseLen);
}
Beispiel #5
0
Node& Grid::NODE(int nID)
{
	op_assert(nID > 0);

	int nPos = whereisNode[nID];
	return (nodes[nPos]);
	//return (nodeIDMap.find(nID));
}
Beispiel #6
0
Face& Grid::FACE(int fID)
{
	op_assert(fID > 0);

	int fPos = whereisFace[fID];
	return(faces[fPos]);
	//return (faceIDMap.find(f));
}
NMErr
EndpointHander::GetStreamEP(void)
{
	DEBUG_ENTRY_EXIT("EndpointHander::GetStreamEP");

	CachedEP		*streamEP = NULL;
	OTLink			*acceptorLink = NULL;
	NMErr			status = kNMNoError;

	//Try_
	{
		//	Get a cached stream ep
		acceptorLink = OTLIFODequeue(&OTEndpoint::sStreamEPCache.Q);
	
		//if there was an available one in the cache
		if (acceptorLink)
		{
			OTAtomicAdd32(-1, &OTEndpoint::sStreamEPCache.readyCount);
			OTAtomicAdd32(-1, &OTEndpoint::sStreamEPCache.totalCount);
			//jacked up and good to go
			mState |= kGotStreamEP;
			
			//get the cache reloading itself
			OTEndpoint::ServiceEPCaches();
		}
		//otherwise, make one now
		else
		{
			return OTAsyncOpenEndpoint(OTCreateConfiguration(mListenerEP->GetStreamProtocolName()), 0, NULL, mNotifier.fUPP, this);
		}

		//	Get the pointer to the cached ep object
		streamEP = OTGetLinkObject(acceptorLink, CachedEP, link);
		op_assert(streamEP != NULL);
		
		//	Remove the notifier that was being used for cacheing and install the "normal" one
		OTRemoveNotifier(streamEP->ep);
		OTInstallNotifier(streamEP->ep, mNotifier.fUPP, this);
		
		mNewEP->mStreamEndpoint->mEP = streamEP->ep;

		delete streamEP;

	}
	//Catch_(code)
	error:
	if (status)
	{
		NMErr code = status;
		return code;
	}
	
	mState |= kStreamDone;
	
	return kNMNoError;
}
Beispiel #8
0
void run_long_int(int size, HashFunc hash_func,
                  void* context, OPHash hasher)
{
  op_assert(size >= 12, "iteration size must > 2^12\n");
  uint64_t i_bound = 1 << size;
  for (uint64_t i = 0; i < i_bound; i++)
    {
      hash_func(&i, context, hasher);
    }
}
ArrayNegativeIndex<T>::ArrayNegativeIndex(int startIndex, int endIndex, T value)
:m_startIndex(startIndex), m_endIndex(endIndex)
{
	op_assert(endIndex >= startIndex);

	int dataSize = endIndex - startIndex;
	m_data.resize(dataSize+1, value);

	//for (int iIndex = 0; iIndex <= dataSize; iIndex++) m_data[iIndex] = value;
}
Beispiel #10
0
/* ----------- private code */
static void initialize_application(
	void)
{
	Handle menubar;
	StringHandle		userName;

#ifndef OP_PLATFORM_MAC_CARBON_FLAG
	MaxApplZone();
	MoreMasters();
	MoreMasters();
	MoreMasters();
	
	InitGraf(&qd.thePort);
	InitFonts();
	InitWindows();
	InitMenus();
	TEInit();
	InitDialogs(NULL);
#else
	MoreMasterPointers(192);
#endif // ! OP_PLATFORM_MAC_CARBON_FLAG

	InitCursor();

	FlushEvents(everyEvent, 0);

	menubar= GetNewMBar(rMENU_BAR_ID);
	op_assert(menubar);

	SetMenuBar(menubar);
	DisposeHandle(menubar);
	AppendResMenu(GetMenuHandle(mApple), 'DRVR');
	DrawMenuBar();

	//	Get the user name from the systemÉ
	
	userName = GetString (-16096);
	if (userName == NULL)
		strcpy(gNameString, "OpenPlay Test");
	else
	{
		doCopyP2CStr(*userName,gNameString);
		ReleaseResource ((Handle) userName);
	}

	// ecf - we wanna enable enumeration by default...
	check_menu_item(mSpecial, iActiveEnumeration, active_enumeration);
	
	//install apple event handler for quitting
	AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,NewAEEventHandlerUPP((AEEventHandlerProcPtr)do_quit_apple_event),0L,false);
	
	return;
}
Beispiel #11
0
NMErr InitOTMemoryReserve(ByteCount freeHeapSpaceRequired, ByteCount chunkSize, 
										   ItemCount minChunks, ItemCount maxChunks)
	// See comment in interface part.
{
	NMErr	err;
	
	if (freeHeapSpaceRequired < 32768)
		freeHeapSpaceRequired = 32768;
	//op_assert(freeHeapSpaceRequired >= 32768);	// Leave less than this in your app heap is extremely dangerous!
	if (chunkSize < 8192)
		chunkSize = 8192;
	//op_assert(chunkSize >= 8192);					// Using this for smaller blocks is pretty silly.
	op_assert(minChunks != 0);					// Passing 0 is silly, and loop below doesnÕt work properly.
	if (minChunks == 0)
		minChunks = 1;
	op_assert(maxChunks != 0);					// Passing 0 is silly, and loop below doesnÕt work properly.
	if (maxChunks == 0)
		maxChunks = minChunks;
	op_assert(maxChunks != 0xFFFFFFFF);			// See comment in header file.
	op_assert(minChunks <= maxChunks);

	op_assert(gMemoryReserve.fHead == nil);		// YouÕve probably initialised the module twice.
	
	gFreeHeapSpaceRequired = freeHeapSpaceRequired;
	gReserveChunkSize = chunkSize;
	gMinReserveChunks = minChunks;
	gReserveChunksAllocated = 0;
	gMaxReserveChunks = maxChunks;

	gReserveInited = true;
	
	err = UpkeepOTMemoryReserve();
	
	if (err == noErr) {
		// Check some post conditions.
		#if DEBUG
			op_assert( (gReserveChunksAllocated >= gMinReserveChunks) && (gReserveChunksAllocated <= gMaxReserveChunks) );
			op_assert( FreeMem() >= freeHeapSpaceRequired );
			op_assert( gReserveChunksAllocated == CountReserveChunks() );
		#endif

	} else {
		// Free up any chunks that we allocated.
		TermOTMemoryReserve();
		gReserveInited = false;
	}

	return err;	
}
Beispiel #12
0
NMUInt32
machine_tick_count(void)
{
#ifdef OP_PLATFORM_MAC_CFM
	return TickCount();
#elif defined(OP_PLATFORM_WINDOWS)
	return GetTickCount();
#else
  struct timeval tp;
  struct timezone tz;
  long result = gettimeofday(&tp,&tz);
  op_assert(result == 0);
  return (tp.tv_sec * 1000) + (tp.tv_usec/1000); //return milliseconds
#endif	
}
Beispiel #13
0
void NewReverse(ERObject **object)
{
	ERObject *oldNext;
	ERObject *newNext = NULL;

	op_assert(object != NULL);
	op_vassert_justreturn(*object != NULL,"NewReverse: *object == NULL");	
	oldNext = (ERObject*)(*object)->fNext;
	
	while (oldNext)
	{
		(*object)->fNext = newNext;
		newNext = *object;
		*object = oldNext;
		oldNext = (ERObject*)(*object)->fNext;
	}
	(*object)->fNext = newNext;
}
Beispiel #14
0
void attach_new_endpoint_to_application(
	struct endpoint_data *endpoint,
	char *title,
	NMBoolean system_time)
{
	static long startLeft = 100;
	static long startTop = 100;
	
	WindowPtr wp;
	char window_title[128];
	
	if(system_time)
	{
		Rect boundsRect;
		boundsRect.left = startLeft;
		startLeft += 32;
		boundsRect.right = boundsRect.left + 500;
		boundsRect.top = startTop;
		startTop += 32;
		boundsRect.bottom = boundsRect.top + 300;
		wp = NewCWindow(nil,&boundsRect,"\pWindow", true, noGrowDocProc,(WindowPtr)-1,false,0);
		//wp = NewCWind(
		//wp= GetNewWindow(winDOCUMENT, NULL, (WindowPtr) -1l);
		op_assert(wp);
		
		//add a close box
		//FIXME: i forgot how to do this on classic =)
#ifdef OP_PLATFORM_MAC_CARBON_FLAG
			ChangeWindowAttributes(wp,kWindowCloseBoxAttribute,0);
		#endif
		
		if(wp)
		{
			SetWRefCon(wp, (long) endpoint);

			strcpy(window_title, title);
			c2pstr(window_title);
			SetWTitle(wp, (const unsigned char *) window_title);
			ShowWindow(wp);
		
			new_log(wp);
		}
	} else {
Beispiel #15
0
PascalHashTable*
PHNew(OPHeap* heap, uint64_t num_objects, double load,
      size_t key_inline_size, size_t valsize)
{
  PascalHashTable* table;
  uint64_t capacity;
  uint32_t capacity_clz, capacity_ms4b, capacity_msb;
  size_t bucket_size;
  void* bucket_ptr;

  op_assert(load > 0.0 && load < 1.0,
            "load %lf must within close interval (0.0, 1.0)\n", load);
  capacity = (uint64_t)(num_objects / load);
  if (capacity < 8)
    capacity = 8;
  capacity_clz = __builtin_clzl(capacity);
  capacity_msb = 64 - capacity_clz;
  capacity_ms4b = round_up_div(capacity, 1UL << (capacity_msb - 4));
  capacity = (uint64_t)capacity_ms4b << (capacity_msb - 4);

  bucket_size = sizeof(oplenref_t) + key_inline_size + valsize;

  table = OPCalloc(heap, 1, sizeof(PascalHashTable));
  if (!table)
    return NULL;
  bucket_ptr = OPCalloc(heap, 1, bucket_size * capacity);
  if (!bucket_ptr)
    {
      OPDealloc(table);
      return NULL;
    }
  table->bucket_ref = OPPtr2Ref(bucket_ptr);
  table->large_data_threshold = DEFAULT_LARGE_DATA_THRESHOLD;
  table->capacity_clz = capacity_clz;
  table->capacity_ms4b = capacity_ms4b;
  table->objcnt_high = (uint64_t)(capacity * load);
  table->objcnt_low = capacity * 2 / 10;
  table->key_inline_size = key_inline_size;
  table->valsize = valsize;
  return table;
}
Beispiel #16
0
OTIPEndpoint::OTIPEndpoint(
	NMEndpointRef	inRef,
	NMUInt32			inMode)
		: OTEndpoint(inRef, inMode)
{	
NMBoolean	success;

//%% TO DO: What happens if the config doesn't cause one or both of these to be setup?
//				Is this OK, or should the process have stopped before we reach this routine?

	//    Each endpoint stores its local and its remote address
    if( mMode & kNMStreamMode && mStreamEndpoint)		//LR make sure we don't crash
    {
		success = AllocAddressBuffer(&mStreamEndpoint->mLocalAddress);
		op_assert(success);
	        OTInitInetAddress((InetAddress*)mStreamEndpoint->mLocalAddress.buf,0,0);
		
		success = AllocAddressBuffer(&mStreamEndpoint->mRemoteAddress);
		op_assert(success);
        OTInitInetAddress((InetAddress*)mStreamEndpoint->mRemoteAddress.buf,0,0);
    }

    if( mMode & kNMDatagramMode && mDatagramEndpoint)		//LR make sure we don't crash
    {
		success = AllocAddressBuffer(&mDatagramEndpoint->mLocalAddress);
		op_assert(success);
	        OTInitInetAddress((InetAddress*)mDatagramEndpoint->mLocalAddress.buf,0,0);
		
		success = AllocAddressBuffer(&mDatagramEndpoint->mRemoteAddress);
		op_assert(success);
        OTInitInetAddress((InetAddress*)mDatagramEndpoint->mRemoteAddress.buf,0,0);
    }
	
	//	Alloc the address buffer for the TCall structure
	success = AllocAddressBuffer(&mCall.addr);
	op_assert(success);
		
	success = AllocAddressBuffer(&mRcvUData.addr);
	op_assert(success);

	mEnumerationResponseData = NULL;
	mEnumerationResponseLen = 0;

	mPreprocessBuffer = new NMUInt8[kQuerySize];
}
Beispiel #17
0
void run_long_keys(int size, HashFunc hash_func,
                   void* context, OPHash hasher)
{
  op_assert(size >= 12, "iteration size must > 2^12\n");
  int i_bound = 1 << (size - 12);
  char uuid [] =
    "!!!!!!--!!!!!!--!!!!!!--!!!!!!--"
    "!!!!!!--!!!!!!--!!!!!!--!!!!!!--"
    "!!!!!!--!!!!!!--!!!!!!--!!!!!!--"
    "!!!!!!--!!!!!!--!!!!!!--!!!!!!--"
    "!!!!!!--!!!!!!--!!!!!!--!!!!!!--"
    "!!!!!!--!!!!!!--!!!!!!--!!!!!!--"
    "!!!!!!--!!!!!!--!!!!!!--!!!!!!--"
    "!!!!!!--!!!!!!--!!!!!!--!!!!!!--";
  uint64_t counter = 0;
  for (int i = 0; i < i_bound; i++)
    {
      for (int j = 2, val = counter >> 12; j < 6; j++, val>>=6)
        {
          for (int k = 0; k < 256; k+=8)
            uuid[j+k] = 0x21 + (val & 0x3F);
        }
      for (int j = 0; j < 64; j++)
        {
          for (int h = 0; h < 256; h+=8)
            uuid[h+1] = 0x21 + j;
          for (int k = 0; k < 64; k++)
            {
              for (int h = 0; h < 256; h+=8)
                uuid[h] = 0x21 + k;
              counter++;
              hash_func(uuid, context, hasher);
            }
        }
    }
}
Beispiel #18
0
 const T & Get (unsigned int I, unsigned int J) const
 {
 	op_assert (I < Size_);
     op_assert (I < ElementSize_);
     return Data_[I*ElementSize_+ J];
 }
Beispiel #19
0
pascal void
EndpointHander::Notifier(
	void		*contextPtr,
	OTEventCode code,
	OTResult	result,
	void		*cookie)
{
	NMErr status;
	DEBUG_ENTRY_EXIT("EndpointHander::Notifier");
	EndpointHander *epHander = (EndpointHander *) contextPtr;

	UNUSED_PARAMETER(result);

	switch (code)
	{
		case T_OPENCOMPLETE:		// one of our endpoints finished opening
		
			//if we were waiting on the stream ep, move on to the datagram ep if necessary
			if (!(epHander->mState & kGotStreamEP))
			{
				epHander->mNewEP->mStreamEndpoint->mEP = (EndpointRef)cookie;	
				epHander->mState |= kGotStreamEP;
				if (!(epHander->mState & kGotDatagramEP))
				{
					OTAsyncOpenEndpoint(OTCreateConfiguration(epHander->mListenerEP->GetDatagramProtocolName()), 0, NULL, epHander->mNotifier.fUPP, contextPtr);
				}
			}
			//it must be our datagram ep that's done
			else
			{
				epHander->mNewEP->mDatagramEndpoint->mEP = (EndpointRef)cookie;		
				epHander->mState |= kGotDatagramEP;				
			}
			
			//once both eps are done, we go ahead and bind
			if ((epHander->mState & kGotStreamEP) && (epHander->mState & kGotDatagramEP))
			{
				//	Bind the endpoint.  Execution continues in the notifier for T_BINDCOMPLETE
				epHander->mBindReq.addr.len = 0;
				epHander->mBindReq.addr.buf = NULL;
				epHander->mBindRet.addr = epHander->mNewEP->mDatagramEndpoint->mLocalAddress;

				//ECF011114 caused problems under MacOSX...
				status = OTBind(epHander->mNewEP->mDatagramEndpoint->mEP, NULL, &epHander->mBindRet);			
				//status = OTBind(epHander->mNewEP->mDatagramEndpoint->mEP, &epHander->mBindReq, &epHander->mBindRet);
				DEBUG_NETWORK_API(epHander->mNewEP->mDatagramEndpoint->mEP, "OTBind", status);								
			}
			break;
			
		case T_BINDCOMPLETE:		// The datagram endpoint has finished
			epHander->mState |= kDatagramDone;
			
			//	by this time, we should have both endpoints ready to go
			op_assert(epHander->mState & (kStreamDone | kDatagramDone) == (kStreamDone | kDatagramDone));
			
			//	we got the local address from the bind
			epHander->mState |= kDatagramLocalAddr;
			
			//	Now that everything is ready, accept the connection
			epHander->Finish();
			break;

		default:
			break;
	}
}
Beispiel #20
0
void
NMEnumerationCallback(
	void *inContext,
	NMEnumerationCommand inCommand, 
	NMEnumerationItem *item)
{
	struct list_item_data *list_data= (struct list_item_data *) inContext;
	short index;

	switch(inCommand)
	{
		case kNMEnumAdd:
			for(index= 0; index<list_data->count; ++index)
			{
				if (list_data->host[index]==item->id) DEBUG_PRINT("Got multiple adds for id %d", item->id);
			}
			
			if (index==list_data->count)
			{
				list_data->host[list_data->count++]= item->id;
				index= add_text_to_list(list_data->dialog, iGameList, item->name);
				op_assert(index==list_data->count-1);
			}
			break;
			
		case kNMEnumDelete:
		{
			NMBoolean found = false;
			for(index= 0; index<list_data->count; ++index)
			{
				if (list_data->host[index]==item->id) 
				{
					found = true;
					// remove from list.
					delete_from_list(list_data->dialog, iGameList, index);
					
					// from cache
					memmove(&list_data->host[index], &list_data->host[index+1], 
						list_data->count-index-1);
					list_data->count--;
					break;
				}
			}
			
			if (!found)
			{
				DEBUG_PRINT("Got a remove for something I don't have in my list?? (%d %s)",item->id, item->name);
			}
			break;
		}
		case kNMEnumClear:
			empty_list(list_data->dialog, iGameList);
			list_data->count= 0;
			break;
			
		default:
			DEBUG_PRINT("Command %d unrecognized in NMEnumerationCallback", inCommand);
			break;

	}
	
	return;
}
Beispiel #21
0
static bool
PHSizeUp(PascalHashTable* table, OPHash hasher)
{
  const size_t key_inline_size = table->key_inline_size;
  const size_t valsize = table->valsize;
  const size_t bucket_size = sizeof(oplenref_t) + key_inline_size + valsize;
  const size_t large_data_threshold = table->large_data_threshold;
  uint8_t* old_buckets;
  uint8_t* new_buckets;
  oplenref_t *recref;
  bool resized;
  uint8_t new_capacity_ms4b, new_capacity_clz;
  uint64_t old_capacity, new_capacity;

  old_capacity = PHCapacity(table);
  old_buckets = OPRef2Ptr(table, table->bucket_ref);

  if (old_capacity * bucket_size >= large_data_threshold)
    {
      // increase size by 20% ~ 33%
      switch(table->capacity_ms4b)
        {
        case 8:
          new_capacity_ms4b = 10;
          new_capacity_clz = table->capacity_clz;
          break;
        case 9:
        case 10:
          new_capacity_ms4b = 12;
          new_capacity_clz = table->capacity_clz;
          break;
        case 11:
        case 12:
          new_capacity_ms4b = 14;
          new_capacity_clz = table->capacity_clz;
          break;
        case 13:
        case 14:
          new_capacity_ms4b = 8;
          new_capacity_clz = table->capacity_clz - 1;
          break;
        case 15:
          new_capacity_ms4b = 10;
          new_capacity_clz = table->capacity_clz - 1;
          break;
        default: op_assert(false, "Unknown capacity_ms4b %d\n",
                           table->capacity_ms4b);
        }
    }
  else
    {
      new_capacity_ms4b = 8;
      new_capacity_clz = table->capacity_ms4b == 8 ?
        table->capacity_clz - 1 : table->capacity_clz - 2;
    }
  new_capacity = PHCapacityInternal(new_capacity_clz, new_capacity_ms4b);
  OP_LOG_INFO(logger, "Resize from %" PRIu64 " to %" PRIu64,
              old_capacity, new_capacity);

  new_buckets = OPCalloc(ObtainOPHeap(table), 1, bucket_size * new_capacity);
  if (!new_buckets)
    {
      OP_LOG_ERROR(logger, "Cannot obtain new bucket for size %" PRIu64,
                   new_capacity);
      return false;
    }

  table->objcnt = 0;
  table->objcnt_high = new_capacity * 8 / 10;
  table->objcnt_low = new_capacity * 2 / 10;
  table->capacity_clz = new_capacity_clz;
  table->capacity_ms4b = new_capacity_ms4b;
  table->longest_probes = 0;
  memset(table->stats, 0x00, sizeof(uint32_t) * PROBE_STATS_SIZE);
  table->bucket_ref = OPPtr2Ref(new_buckets);

  for (uint64_t idx = 0; idx < old_capacity; idx++)
    {
      recref = (oplenref_t*)&old_buckets[idx * bucket_size];
      if (!OPLenRefIsEmpty(*recref) &&
          !OPLenRefIsDeleted(*recref))
        {
          PHUpsertPushDown(table, hasher, &old_buckets[idx * bucket_size],
                           0, NULL, &resized);
        }
    }
  OPDealloc(old_buckets);
  return true;
}
Beispiel #22
0
static bool
PHSizeDown(PascalHashTable* table, OPHash hasher)
{
  const size_t key_inline_size = table->key_inline_size;
  const size_t valsize = table->valsize;
  const size_t bucket_size = sizeof(oplenref_t) + key_inline_size + valsize;
  uint8_t* old_buckets;
  uint8_t* new_buckets;
  uint8_t new_capacity_ms4b, new_capacity_clz;
  uint64_t old_capacity, new_capacity;
  oplenref_t *recref;
  bool resized;

  old_capacity = PHCapacity(table);
  old_buckets = OPRef2Ptr(table, table->bucket_ref);
  op_assert(old_capacity > 16,
            "Can not resize smaller than 16, but got old_capacity %"
            PRIu64 "\n", old_capacity);

  switch(table->capacity_ms4b)
    {
    case 8:  // new load 0.45
    case 9:  // new load 0.50
    case 10: // new load 0.55
    case 11: // new load 0.60
      new_capacity_ms4b = 8;
      new_capacity_clz = table->capacity_clz + 1;
      break;
    case 12: // new load 0.40
    case 13: // new load 0.43
    case 14: // new load 0.46
    case 15: // new load 0.50
      new_capacity_ms4b = 12;
      new_capacity_clz = table->capacity_clz + 1;
      break;
    default: op_assert(false, "Unknown capacity_ms4b %d\n",
                       table->capacity_ms4b);
    }

  new_capacity = PHCapacityInternal(new_capacity_clz, new_capacity_ms4b);
  OP_LOG_INFO(logger, "Resize from %" PRIu64 " to %" PRIu64,
              old_capacity, new_capacity);
  new_buckets = OPCalloc(ObtainOPHeap(table), 1, bucket_size * new_capacity);
  if (!new_buckets)
    {
      OP_LOG_ERROR(logger, "Cannot obtain new bucket for size %" PRIu64,
                   new_capacity);
      return false;
    }

  table->objcnt = 0;
  table->objcnt_high = new_capacity * 8 / 10;
  table->objcnt_low = new_capacity * 2 / 10;
  table->capacity_clz = new_capacity_clz;
  table->capacity_ms4b = new_capacity_ms4b;
  table->longest_probes = 0;
  memset(table->stats, 0x00, sizeof(uint32_t) * PROBE_STATS_SIZE);
  table->bucket_ref = OPPtr2Ref(new_buckets);

  for (uint64_t idx = 0; idx < old_capacity; idx++)
    {
      recref = (oplenref_t*)&old_buckets[idx * bucket_size];
      if (!OPLenRefIsEmpty(*recref) &&
          !OPLenRefIsDeleted(*recref))
        {
          PHUpsertPushDown(table, hasher, &old_buckets[idx * bucket_size],
                           0, NULL, &resized);
        }
    }
  OPDealloc(old_buckets);
  return true;
}
Beispiel #23
0
NMErr
EndpointHander::GetDatagramEP(void)
{
	DEBUG_ENTRY_EXIT("EndpointHander::GetDatagramEP");

	CachedEP		*datagramEP = NULL;
	OTLink			*acceptorLink = NULL;
	NMErr		status = kNMNoError;

	//	if we're not in uber mode, there should be no datagram ep
	//	just jump to the notifier
	if (mNewEP->mMode != kNMNormalMode)
	{
		Notifier(this, T_BINDCOMPLETE, kNMNoError, NULL);
		return kNMNoError;
	}
		
	//Try_
	{
		//	Get a datagram endpoint from the cache
		acceptorLink = OTLIFODequeue(&OTEndpoint::sDatagramEPCache.Q);
		if (acceptorLink)
		{
			OTAtomicAdd32(-1, &OTEndpoint::sDatagramEPCache.readyCount);
			OTAtomicAdd32(-1, &OTEndpoint::sDatagramEPCache.totalCount);
			
			//jacked up and good to go
			mState |= kGotDatagramEP;
			
			//get the cache reloading itself
			OTEndpoint::ServiceEPCaches();
		}
		//if we couldn't get one off the cache, we'll make one after we have a stream endpoint
		// (one at a time for simplicity)
		else
		{
			if (mState & kGotStreamEP)
			{
				return OTAsyncOpenEndpoint(OTCreateConfiguration(mListenerEP->GetDatagramProtocolName()), 0, NULL, mNotifier.fUPP, this);
			}
			return kNMNoError; //we just wait for the stream endpoint to get done
		}

		//	Get the pointer to the cached ep object
		datagramEP = OTGetLinkObject(acceptorLink, CachedEP, link);
		op_assert(datagramEP != NULL);
		
		//	Remove the notifier that was being used for cacheing and install the "normal" one
		OTRemoveNotifier(datagramEP->ep);
		OTInstallNotifier(datagramEP->ep, mNotifier.fUPP, this);

		mNewEP->mDatagramEndpoint->mEP = datagramEP->ep;
		
		delete datagramEP;
		
		//if we got both endpoints, go ahead and bind here
		if (mState & kGotStreamEP)
		{
			//	Bind the endpoint.  Execution continues in the notifier for T_BINDCOMPLETE
			mBindReq.addr.len = 0;
			mBindReq.addr.buf = NULL;
			mBindRet.addr = mNewEP->mDatagramEndpoint->mLocalAddress;

			status = OTBind(mNewEP->mDatagramEndpoint->mEP,NULL, &mBindRet);
			//status = OTBind(mNewEP->mDatagramEndpoint->mEP,&mBindReq, &mBindRet);

			DEBUG_NETWORK_API(mNewEP->mDatagramEndpoint->mEP, "OTBind", status);					
			//ThrowIfOSErr_(status);
			if (status)
				goto error;
		}
	}
	//Catch_(code)
	error:
	if (status)
	{
		NMErr code = status;
		return code;
	}
	
	return kNMNoError;
}
Beispiel #24
0
static NMErr
ParseConfigString(
    const char		*inConfigStr,
    NMType			inGameID,
    const char		*inGameName,
    const void		*inEnumData,
    NMUInt32			inDataLen,
    NMIPConfigPriv	*outConfig)
{
    NMErr	status = kNMNoError;
    NMInetPort	port = GenerateDefaultPort(inGameID);
    InetHost	host = 0x7f000001;		// loopback address
    NMBoolean	gotToken;
    NMSInt32	tokenLen;
    char		workString[kMaxHostNameLen + 1];
    NMUInt32		p;

    outConfig->type = kModuleID;
    outConfig->version = kVersion;

    outConfig->gameID = inGameID;
    outConfig->connectionMode = kNMNormalMode;

    if (inGameName)
    {
        strncpy(outConfig->name, inGameName, kMaxGameNameLen);
        outConfig->name[kMaxGameNameLen]= 0;
    }
    else
    {
        strcpy(outConfig->name, "unknown");
    }

    if (inDataLen)
    {
        if (inDataLen > kNMEnumDataLen)
            return kNMInvalidConfigErr;

        op_assert(inDataLen <= kNMEnumDataLen);
        machine_move_data(inEnumData, outConfig->customEnumData, inDataLen);
        outConfig->customEnumDataLen = inDataLen;
    }
    else
    {
        outConfig->customEnumDataLen = 0;
    }

    if (OTUtils::OTInitialized())
    {
        OTInitInetAddress((InetAddress *)&outConfig->address, port, host);
    }
    else
    {
        op_vpause("Classic not supported!");
    }

    //  default netSprocketMode
    outConfig->netSprocketMode = kDefaultNetSprocketMode;

    //	If we got a null string, just create a default config
    if (inConfigStr == NULL)
        return kNMNoError;

    //Try_
    {
        //	Generic module information

        //	Read the type
        tokenLen = sizeof (NMType);
        gotToken = get_token(inConfigStr, kConfigModuleType, LONG_DATA, &outConfig->type, &tokenLen);
        if (!gotToken)
            outConfig->type = kModuleID;

        //	Read the version
        tokenLen = sizeof (NMUInt32);
        gotToken = get_token(inConfigStr, kConfigModuleVersion, LONG_DATA, &outConfig->version, &tokenLen);

        if (!gotToken)
            outConfig->version = kVersion;

        //	Read the game id
        tokenLen = sizeof (NMUInt32);
        gotToken = get_token(inConfigStr, kConfigGameID, LONG_DATA, &outConfig->gameID, &tokenLen);

        if (!gotToken)
            outConfig->gameID = 0;

        //	Read the game name
        if (inGameName == NULL || inGameName[0] == 0)
        {
            tokenLen = kMaxGameNameLen;
            gotToken = get_token(inConfigStr, kConfigGameName, STRING_DATA, &outConfig->name, &tokenLen);

            if (!gotToken)
                strcpy(outConfig->name, "unknown");
        }

        //	Read the connection mode
        tokenLen = sizeof (NMUInt32);
        gotToken = get_token(inConfigStr, kConfigEndpointMode, LONG_DATA, &outConfig->connectionMode, &tokenLen);

        if (! gotToken)
            outConfig->connectionMode = kNMNormalMode;

        //	Read the netSprocketMode mode
        tokenLen = sizeof (NMBoolean);
        gotToken = get_token(inConfigStr, kConfigNetSprocketMode, BOOLEAN_DATA, &outConfig->netSprocketMode, &tokenLen);

        if (!gotToken)
            outConfig->netSprocketMode = kDefaultNetSprocketMode;

        //	read the custom data, if any
        if (inDataLen == 0)
        {
            tokenLen = kNMEnumDataLen;
            gotToken = get_token(inConfigStr, kConfigCustomData, BINARY_DATA, &outConfig->customEnumData, &tokenLen);

            if (gotToken)
                outConfig->customEnumDataLen = tokenLen;
        }

        //	IP Module-specific information

        //	Read the dotted quad IP address
        tokenLen = kMaxHostNameLen;
        gotToken = get_token(inConfigStr, kIPConfigAddress, STRING_DATA, workString, &tokenLen);

        if (! gotToken)
        {
            outConfig->address.fHost = host;
        }
        else
        {
            //	This is OT-dependent, and could cause the PPP module to dial-in.
            //	It will also fail if DNS is not available
            status = OTUtils::MakeInetAddressFromString(workString, &outConfig->address);
        }

        if (outConfig->address.fPort == 0)
            outConfig->address.fPort = port;

        //	Read the port.  We don't care if it's not present.  It might have been in the address
        tokenLen = sizeof (NMUInt32);
        gotToken = get_token(inConfigStr, kIPConfigPort, LONG_DATA, &p, &tokenLen);

        if (gotToken)
            outConfig->address.fPort = p;

        return kNMNoError;
    }
    //Catch_(code)
error:
    if (status)
    {
        NMErr code = status;
        return code;
    }
    return status;
}
Beispiel #25
0
	// CF-02: Resize data (I)
	void Resize(unsigned int I)
	{
		op_assert(ElementSize_ > 0);
		Data_.resize(I * ElementSize_);
		Size_	= I;
	}