Esempio n. 1
0
XBOX::VJSObject	VJSSharedWorkerClass::MakeConstructor (XBOX::VJSContext inContext)
{
	XBOX::VJSObject	constructor =
		JS4DMakeConstructor(inContext, Class(), _Construct, false,	VJSSharedWorkerClass::sConstrFunctions );

	XBOX::VJSArray	listArray(inContext);
	
	constructor.SetProperty("list", listArray, JS4D::PropertyAttributeDontDelete);	

	return constructor;
}
Esempio n. 2
0
void VJSSharedWorkerClass::_Construct (VJSParms_construct &ioParms)
{
	if (!ioParms.CountParams()
	|| !ioParms.IsStringParam(1)
	|| (ioParms.CountParams() >= 2 && !ioParms.IsStringParam(2))) {
	
		XBOX::vThrowError(XBOX::VE_INVALID_PARAMETER);
		return;

	}

	XBOX::VJSContext	context(ioParms.GetContext());
	XBOX::VString		url, name;
	bool				reUseContext;
	VJSWorker			*outsideWorker;
	VJSWebWorkerObject	*workerProxy;	
#if USE_V8_ENGINE
	XBOX::VJSObject constructedObject = ioParms.fConstructedObject;
#else
	XBOX::VJSObject	constructedObject(context);
#endif


	ioParms.GetStringParam(1, url);
	if (ioParms.CountParams() == 2)

		ioParms.GetStringParam(2, name);

	outsideWorker = VJSWorker::RetainWorker(context);

	if (ioParms.CountParams() < 3 || !ioParms.IsBooleanParam(3) || !ioParms.GetBoolParam(3, &reUseContext))

		reUseContext = false;

	if ((workerProxy = VJSWebWorkerObject::_CreateWorker(context, outsideWorker, reUseContext, NULL, url, false, name)) != NULL) {

		constructedObject = VJSSharedWorkerClass::ConstructInstance(ioParms, workerProxy);
		workerProxy->fOnErrorPort->SetObject(outsideWorker, constructedObject);

		XBOX::VJSObject	messagePortObject(context);
		
		messagePortObject = VJSMessagePortClass::CreateInstance(context, workerProxy->fOnMessagePort);
		workerProxy->fOnMessagePort->SetObject(outsideWorker, messagePortObject);
		constructedObject.SetProperty("port", messagePortObject);

		_AddToList(context, "SharedWorker", constructedObject);

	}

	ioParms.ReturnConstructedObject(constructedObject);

	XBOX::ReleaseRefCountable<VJSWorker>(&outsideWorker);
}
void VJSNetServerSyncClass::_accept (XBOX::VJSParms_callStaticFunction &ioParms, VJSNetServerObject *inServer)
{
	xbox_assert(inServer != NULL);

	sLONG	timeOut;

	if (ioParms.CountParams() >= 1) {

		if (!ioParms.IsNumberParam(1) || !ioParms.GetLongParam(1, &timeOut)) {

			XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_NUMBER, "1");
			return;

		}

		if (timeOut < 0) {

			XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_NUMBER, "1");
			return;

		}

	} else

		timeOut = 0;

	XBOX::XTCPSock	*socket;

	// If socket returned is NULL, accept() has timed out or an error has occured.
	// An exception is thrown by GetNewConnectedSocket() if erroneous.

	if ((socket = inServer->fSockListener->GetNewConnectedSocket(timeOut)) == NULL) 

		ioParms.ReturnNullValue();

	else {

		XBOX::VTCPEndPoint	*endPoint		= NULL;
		VJSNetSocketObject	*socketObject	= NULL;
	
		if ((endPoint = new XBOX::VTCPEndPoint(socket)) == NULL 
		|| (socketObject = new VJSNetSocketObject(true, VJSNetSocketObject::eTYPE_TCP4, false)) == NULL) {

			if (endPoint != NULL)

				endPoint->Release();

			if (socketObject != NULL)

				socketObject->Release();

			socket->Close();
			delete socket;

			XBOX::vThrowError(XBOX::VE_MEMORY_FULL);
		
		} else {

			socketObject->fEndPoint = endPoint;
			socketObject->fEndPoint->SetNoDelay(false);

			XBOX::VJSObject	newSocketSync = VJSNetSocketSyncClass::CreateInstance(ioParms.GetContext(), socketObject);
			XBOX::VString	address;

			socketObject->fObjectRef = newSocketSync.GetObjectRef();
			socketObject->fWorker = VJSWorker::RetainWorker(ioParms.GetContext());

			socketObject->fEndPoint->GetIP(address);
			newSocketSync.SetProperty("remoteAddress", address);
			newSocketSync.SetProperty("remotePort", (sLONG) socketObject->fEndPoint->GetPort() & 0xffff);

			ioParms.ReturnValue(newSocketSync);

		}

	}
}