Ejemplo n.º 1
0
NMErr
EndpointHander::Finish(void)
{
	DEBUG_ENTRY_EXIT("EndpointHander::Finish");

NMErr	status;
		
	OTRemoveNotifier(mNewEP->mStreamEndpoint->mEP);
	OTInstallNotifier(mNewEP->mStreamEndpoint->mEP, mNewEP->mNotifier.fUPP, mNewEP->mStreamEndpoint);

	if (mNewEP->mMode == kNMNormalMode)
	{
		OTRemoveNotifier(mNewEP->mDatagramEndpoint->mEP);
		OTInstallNotifier(mNewEP->mDatagramEndpoint->mEP, mNewEP->mNotifier.fUPP, mNewEP->mDatagramEndpoint);
	}
	
	status = OTAccept(mListenerEP->mStreamEndpoint->mEP, mNewEP->mStreamEndpoint->mEP, mCall);
	DEBUG_NETWORK_API(mListenerEP->mStreamEndpoint->mEP, "OTAccept", status);					

	if (status == kOTLookErr)
	{
		OTResult lookResult = OTLook(mListenerEP->mStreamEndpoint->mEP);

		if (lookResult == T_DISCONNECT)		// the active peer disconnected
			OTRcvDisconnect(mListenerEP->mStreamEndpoint->mEP, NULL);
			
		//	fake the accept complete
		mListenerEP->HandleAcceptComplete();
		
		//	kill the new endpoint
		EndpointDisposer *killer = new EndpointDisposer(mNewEP, true);
	}
	
	if (! ScheduleDelete())
		delete this;		// this is pretty damn likely to crach [gg]
	
	return kNMNoError;
}
Ejemplo n.º 2
0
OSStatus ot_DNRInit(void)
{
	OSStatus theError = kOTNoError;

	// First, check to see if we've already initialized.  If so, then just return...
	if( gDNRep != kOTInvalidProviderRef){
		return (kOTNoError);
	}

	// Next, check to see if any OT service has been used yet
	if (!gOTInited){
		theError = ot_OpenDriver();
	}

	// Get the internet services reference for DNS
	if( theError == kOTNoError){
#if TARGET_API_MAC_CARBON
		gDNRep = OTOpenInternetServicesInContext( kDefaultInternetServicesPath, 0, &theError, NULL);
#else
		gDNRep = OTOpenInternetServices( kDefaultInternetServicesPath, 0, &theError);
#endif
	}

	/* We have to choose to be synchronous or async, sync is simpler but
	 *	I think that async could be done in the future
	 */
	if( theError == kOTNoError){
		theError = OTSetSynchronous( gDNRep);
	}

	// Give OT a pointer to a notifier function that handles async events
	if( theError == kOTNoError){
		gDNRYieldNotifyUPP = NewOTNotifyUPP(DNRYieldNotifier);
		theError = OTInstallNotifier(gDNRep, gDNRYieldNotifyUPP, nil);
	}

	/* If we get idle events, then implementing a multi-threaded app shouldn't
	 *	be any big deal
	 */
	if( theError == kOTNoError){
		theError = OTUseSyncIdleEvents(gDNRep, true);
	}
	return( theError);
}
Ejemplo n.º 3
0
void _MD_InitNetAccess()
{
	OSErr		err;
	OSStatus    errOT;
	PRBool 		hasOTTCPIP = PR_FALSE;
	PRBool 		hasOT = PR_FALSE;
	long 		gestaltResult;
	PRThread *me = _PR_MD_CURRENT_THREAD();
	
	err = Gestalt(gestaltOpenTpt, &gestaltResult);
	if (err == noErr)
		if (gestaltResult & GESTALT_OPEN_TPT_PRESENT)
			hasOT = PR_TRUE;
	
	if (hasOT)
		if (gestaltResult & GESTALT_OPEN_TPT_TCP_PRESENT)
			hasOTTCPIP = PR_TRUE;
		
	PR_ASSERT(hasOTTCPIP == PR_TRUE);

	errOT = InitOpenTransport();
	PR_ASSERT(err == kOTNoError);

	sSvcRef = OTOpenInternetServices(kDefaultInternetServicesPath, NULL, &errOT);
	if (errOT != kOTNoError) return;	/* no network -- oh well */
	PR_ASSERT((sSvcRef != NULL) && (errOT == kOTNoError));

    /* Install notify function for DNR Address To String completion */
	errOT = OTInstallNotifier(sSvcRef, NotifierRoutine, me);
	PR_ASSERT(errOT == kOTNoError);

    /* Put us into async mode */
	errOT = OTSetAsynchronous(sSvcRef);
	PR_ASSERT(errOT == kOTNoError);

/* XXX Does not handle absence of open tpt and tcp yet! */
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
0
NMErr
OTIPEnumerator::StartEnumeration(void)
{
	TEndpointInfo	info;
	NMErr			status = kNMNoError;
	TBind			request;
	TOption			optBuf;
	//NMUInt8			optBuf[64];
	//NMUInt8			fooBuf[32];
	TOptMgmt		cmd;
	//NMUInt8 			*foo = fooBuf;

	
	//	If they don't want us to actively get the enumeration, there is nothing to do
	if (! bActive)
		return kNMNoError;
	
	//	first clear out any current items
	(mCallback)(mContext, kNMEnumClear, NULL);	// [Edmark/PBE] 11/16/99 added

	bFirstIdle = true;
	
	//	Create an OT endpoint
	mEP = OTOpenEndpoint(OTCreateConfiguration(kUDPName), 0, &info, &status);
	if (status)
		goto error;

	// fill in the option request
	cmd.flags = T_NEGOTIATE;
	cmd.opt.len = kOTFourByteOptionSize;
	cmd.opt.maxlen = kOTFourByteOptionSize;
	cmd.opt.buf = (NMUInt8*)&optBuf;

	// fill in the toption struct
	optBuf.len = sizeof(TOption);
	optBuf.level = INET_IP;
	optBuf.name = kIP_BROADCAST;
	optBuf.status = 0;
	optBuf.value[0] = 1;

/*
	cmd.opt.len = 0;
	cmd.opt.maxlen = 64;
	cmd.opt.buf = (NMUInt8*)optBuf;
	cmd.flags = T_NEGOTIATE;

	//	Option management kinda sucks
	strcpy((char *) fooBuf, "Broadcast = 1");
	status = OTCreateOptions(kRawIPName, (char **)&foo, &cmd.opt);
*/

	status = OTOptionManagement(mEP, &cmd, &cmd);
	if (status)
		goto error;
	
	//	Allocate the buffer for receiving the endpoint
	mIncomingData.udata.buf = (NMUInt8 *) InterruptSafe_alloc(info.tsdu);
	if (mIncomingData.udata.buf == NULL){
		status = kNSpMemAllocationErr;
		goto error;
	}
	
	mIncomingData.udata.maxlen = info.tsdu;
	
	//	Bind it
	request.addr.buf = NULL;
	request.addr.len = 0;
	request.addr.maxlen = 0;
	request.qlen = 0;
	
	status = OTBind(mEP, &request, NULL);
	if (status)
		goto error;

	OTSetNonBlocking(mEP);
	
	//	Get our interface info (for the broadcast address)
	//	Do this after we bind so that we know the interface is live
	if (! bGotInterfaceInfo)
	{
		status = OTInetGetInterfaceInfo(&mInterfaceInfo, kDefaultInetInterface);
		if (status)
			goto error;
		
		bGotInterfaceInfo = true;
	}
	
	//	Install notifier
	status = OTInstallNotifier(mEP, mNotifier.fUPP, this);
	if (status)
		goto error;
	
	//	Make is asynchronous
	status = OTSetAsynchronous(mEP);
	if (status)
		goto error;
	
	//	Send out the query
	mEnumPeriod = 250;
	status = SendQuery();

error:
	if (status)
	{
		if (mEP)
		{
			OTCloseProvider(mEP);			// ignore errors
			mEP = kOTInvalidEndpointRef;
		}
	}
	return status;
}