Exemplo n.º 1
0
void RPCServer::bind(int port)
{
	// Uses the protocol combined with the endpoint for receiving
	// remote procedure calls.
	status = RpcServerUseProtseqEp(
		reinterpret_cast<unsigned char*>("ncacn_ip_tcp"), // Use TCP/IP protocol.
		RPC_C_PROTSEQ_MAX_REQS_DEFAULT, // Backlog queue length for TCP/IP.
		reinterpret_cast<unsigned char*>("4747"), // TCP/IP port to use.
		NULL); // No security.

	if (status)
		exit(status);
	
	// Registers the Example1Explicit interface.
	status = RpcServerRegisterIf2(
		AVInterface_v1_0_s_ifspec, // Interface to register.
		NULL, // Use the MIDL generated entry-point vector.
		NULL, // Use the MIDL generated entry-point vector.
		RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH, // Forces use of security callback.
		RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Use default number of concurrent calls.
		(unsigned)-1, // Infinite max size of incoming data blocks.
		SecurityCallback); // Naive security callback.

	if (status)
		exit(status);

}
Exemplo n.º 2
0
//Function to create a RPC server and wait, should be called using a worker thread.
DWORD WINAPI PrtDistCreateRPCServerForEnqueueAndWait(LPVOID portNumber)
{
	PrtDistLog("Creating RPC server for Enqueue at Port :");
	RPC_STATUS status;
	char buffPort[100];
	_itoa(*((PRT_INT32*)portNumber), buffPort, 10);
	PrtDistLog(buffPort);
	status = RpcServerUseProtseqEp(
		(unsigned char*)("ncacn_ip_tcp"), // Use TCP/IP protocol.
		RPC_C_PROTSEQ_MAX_REQS_DEFAULT, // Backlog queue length for TCP/IP.
		(RPC_CSTR)buffPort, // TCP/IP port to use.
		NULL);

	if (status)
	{
		PrtDistLog("Runtime reported exception in RpcServerUseProtseqEp");
		exit(status);
	}

	status = RpcServerRegisterIf2(
		s_PrtDist_v1_0_s_ifspec, // Interface to register.
		NULL, // Use the MIDL generated entry-point vector.
		NULL, // Use the MIDL generated entry-point vector.
		RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH, // Forces use of security callback.
		RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Use default number of concurrent calls.
		(unsigned)-1, // Infinite max size of incoming data blocks.
		NULL); // Naive security callback.

	if (status)
	{
		PrtDistLog("Runtime reported exception in RpcServerRegisterIf2");
		exit(status);
	}

	PrtDistLog("Receiver listening ...");
	// Start to listen for remote procedure calls for all registered interfaces.
	// This call will not return until RpcMgmtStopServerListening is called.
	status = RpcServerListen(
		1, // Recommended minimum number of threads.
		RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Recommended maximum number of threads.
		0);

	if (status)
	{
		PrtDistLog("Runtime reported exception in RpcServerListen");
		exit(status);
	}

	return -1;

}
Exemplo n.º 3
0
HRESULT StartServer( const wchar_t* sessionGuidStr )
{
    HRESULT         hr = S_OK;
    RPC_STATUS      rpcRet = RPC_S_OK;
    bool            registered = false;
    std::wstring    endpoint( AGENT_EVENT_IF_LOCAL_ENDPOINT_PREFIX );

    endpoint.append( sessionGuidStr );

    rpcRet = RpcServerUseProtseqEp(
                 AGENT_LOCAL_PROTOCOL_SEQUENCE,
                 RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
                 (RPC_WSTR) endpoint.c_str(),
                 NULL );
    if ( rpcRet != RPC_S_OK )
    {
        hr = HRESULT_FROM_WIN32( rpcRet );
        goto Error;
    }

    rpcRet = RpcServerRegisterIf2(
                 MagoRemoteEvent_v1_0_s_ifspec,
                 NULL,
                 NULL,
                 RPC_IF_ALLOW_LOCAL_ONLY,
                 RPC_C_LISTEN_MAX_CALLS_DEFAULT,
                 (unsigned int) -1,
                 NULL );
    if ( rpcRet != RPC_S_OK )
    {
        hr = HRESULT_FROM_WIN32( rpcRet );
        goto Error;
    }
    registered = true;

    rpcRet = RpcServerListen( 1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE );
    if ( rpcRet != RPC_S_OK )
    {
        hr = HRESULT_FROM_WIN32( rpcRet );
        goto Error;
    }

Error:
    if ( FAILED( hr ) )
    {
        if ( registered )
            RpcServerUnregisterIf( MagoRemoteEvent_v1_0_s_ifspec, NULL, FALSE );
    }
    return hr;
}
Exemplo n.º 4
0
int main()
{
	
	// Create Handle
	RpcServerUseProtseqEpA(RPC_CSTR("ncacn_ip_tcp"),10, RPC_CSTR("8080"),NULL);

	// Register Server Inrerface
	RpcServerRegisterIf2(
		Server_v1_0_s_ifspec,
		NULL, NULL, RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH,10,(unsigned)-1,SecurityCallbackOK
	);

	// Start Listening
	std::cout << "Listening on port 8080 ..." << std::endl;
	RpcServerListen(1,10,FALSE);

}
Exemplo n.º 5
0
int main()
{
    RPC_STATUS status;

    // Uses the protocol combined with the endpoint for receiving
    // remote procedure calls.
    status = RpcServerUseProtseqEp(
                 reinterpret_cast<unsigned char*>("ncacn_ip_tcp"), // Use TCP/IP protocol.
                 RPC_C_PROTSEQ_MAX_REQS_DEFAULT, // Backlog queue length for TCP/IP.
                 reinterpret_cast<unsigned char*>("4747"), // TCP/IP port to use.
                 NULL); // No security.

    if (status)
        exit(status);

    // Registers the Example1Explicit interface.
    status = RpcServerRegisterIf2(
                 Example1Explicit_v1_0_s_ifspec, // Interface to register.
                 NULL, // Use the MIDL generated entry-point vector.
                 NULL, // Use the MIDL generated entry-point vector.
                 RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH, // Forces use of security callback.
                 RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Use default number of concurrent calls.
                 (unsigned)-1, // Infinite max size of incoming data blocks.
                 SecurityCallback); // Naive security callback.

    if (status)
        exit(status);

    // Start to listen for remote procedure calls for all registered interfaces.
    // This call will not return until RpcMgmtStopServerListening is called.
    status = RpcServerListen(
                 1, // Recommended minimum number of threads.
                 RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Recommended maximum number of threads.
                 FALSE); // Start listening now.

    if (status)
        exit(status);
}
Exemplo n.º 6
0
HRESULT JsInitializeJITServer(
    __in UUID* connectionUuid,
    __in_opt void* securityDescriptor,
    __in_opt void* alpcSecurityDescriptor)
{
    RPC_STATUS status;
    RPC_BINDING_VECTOR* bindingVector = NULL;
    UUID_VECTOR uuidVector;

    uuidVector.Count = 1;
    uuidVector.Uuid[0] = connectionUuid;

    status = RpcServerUseProtseqW(
        (RPC_WSTR)L"ncalrpc",
        RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
        alpcSecurityDescriptor);
    if (status != RPC_S_OK)
    {
        return status;
    }

#ifndef NTBUILD
    status = RpcServerRegisterIf2(
        ServerIChakraJIT_v0_0_s_ifspec,
        NULL,
        NULL,
        RPC_IF_AUTOLISTEN,
        RPC_C_LISTEN_MAX_CALLS_DEFAULT,
        (ULONG)-1,
        NULL);
#else
    status = RpcServerRegisterIf3(
        ServerIChakraJIT_v0_0_s_ifspec,
        NULL,
        NULL,
        RPC_IF_AUTOLISTEN,
        RPC_C_LISTEN_MAX_CALLS_DEFAULT,
        (ULONG)-1,
        NULL,
        securityDescriptor);
#endif
    if (status != RPC_S_OK)
    {
        return status;
    }
    status = RpcServerInqBindings(&bindingVector);
    if (status != RPC_S_OK)
    {
        return status;
    }

    status = RpcEpRegister(
        ServerIChakraJIT_v0_0_s_ifspec,
        bindingVector,
        &uuidVector,
        NULL);

    RpcBindingVectorFree(&bindingVector);

    if (status != RPC_S_OK)
    {
        return status;
    }
    JITManager::GetJITManager()->SetIsJITServer();

    status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, FALSE);

    return status;
}
Exemplo n.º 7
0
//------------------------------------------------------------------
bool AVEngine::Start()
{	 
	RPC_STATUS status;
	unsigned int   nMinCalls           = DEFAULT_MIN_CALLS ;
	unsigned int   nMaxCalls           = DEFAULT_MAX_CALLS ;
	wchar_t   *pszProtocolSequence     = DEFAULT_PROTOCOL_SEQUENCE ; // for "RpcServerUseProtseqEp" proper work, we change it's declaration from " unsigned char *" to "wchar_t   *" 
	wchar_t   *pszEndpoint             = DEFAULT_ENDPOINT ;

	//tells the RPC run-time library to use the specified protocol sequence combined with the specified endpoint for receiving remote procedure calls.
	status = RpcServerUseProtseqEp((RPC_WSTR)pszProtocolSequence,nMaxCalls,(RPC_WSTR)pszEndpoint,NULL);
	if (status != RPC_S_OK)
	{
		PutLog(RPCSERVERUSEPROTSEQEP_FAILD);
		return false ;
	}
	status = RpcServerRegisterIf2(AVEngine_AsyncRPC_v1_0_s_ifspec, // interface to register
		NULL,   // MgrTypeUuid
		NULL,// MgrEpv; null means use default
		RPC_IF_ALLOW_LOCAL_ONLY, //the RPC runtime rejects calls made by remote clients. All local calls using ncadg_* and ncacn_* protocol sequences are also rejected, with the exception of ncacn_np.
		nMaxCalls,//Maximum number of concurrent remote procedure call requests the server can accept on an auto-listen interface.
		NULL,//Maximum size of incoming data blocks, in bytes. * This parameter has no effect on calls made over the ncalrpc protocol.
		NULL);//Security-callback function, or NULL for no callback.
	// Create new thread for listen to client requests 
	if (status != RPC_S_OK)
	{
		PutLog(RPCSERVERREGISTERIF2_FAILD);
		return false ;
	}

	PutLog(CALLING_RPCSERVERLISTEN);
	//signals the RPC run-time library to listen for remote procedure calls.
	status = RpcServerListen(nMinCalls, //Hint to the RPC run time that specifies the minimum number of call threads that should be created and maintained in the given server. 
		nMaxCalls, //Recommended maximum number of concurrent remote procedure calls the server can execute.
		1  //A value of nonzero indicates that RpcServerListen should return immediately after completing function processing. 
		);

	if (status != RPC_S_OK)
	{
		RpcServerUnregisterIf(AVEngine_AsyncRPC_v1_0_s_ifspec, NULL, FALSE);
		PutLog(RPCSERVERLISTEN_FAILD);
		return false ;
	}
	PutLog(CALLING_RPCSERVERLISTEN);
	hThread = CreateThread(
		NULL,              // default security attributes
		0,                 // use default stack size  
		SetupRPCServer,          // thread function 
		NULL,             // argument to thread function 
		0,                 // use default creation flags 
		&dwThreadId
		);   // returns the thread identifier 

	
	
	// Check the return value for success.
	if (hThread == NULL) 
	{	
		PutLog(CREATELISTENTHREAD_FAILD);
		return false;
	}
	return true;	
}