Hold Render Process until message recieved

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Hold Render Process until message recieved

Postby Albus » Thu Mar 22, 2018 4:26 am

Hi, I'm currently trying to implement cef in an application, where I need inter process communication. Now I have the sitation that I am inside a render process and send a process message to the browser process. Than the browser process is doing some work and sends a process message back to the render process.
The problem is that i have to wait in the render process until the process message comes back. I tried following but it doesn't works (it's Delphi code, but it's not complicated)
Code: Select all
while not FSubprocessCallbackList.Items[callId].Return do
 begin
   Sleep(5);
   cef_do_message_loop_work;
 end;


The problem is that the process message from the browser process to the render process is not recieved in the render process. I though that cef_do_message_loop_work does this but apparently not. Is there an other way to make the render process recieving the process message?
Don't ask why I'm doing this, please. I know that this is not very clean, but I have to synchronize this process messages.
Albus
 

Re: Hold Render Process until message recieved

Postby magreenblatt » Thu Mar 22, 2018 12:44 pm

Indeed, if you block the renderer process main thread you will not receive incoming messages. What are you trying to accomplish?
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: Hold Render Process until message recieved

Postby Czarek » Thu Mar 22, 2018 2:01 pm

The Renderer process can execute javascript code synchronously, and javascript can make a synchronous XHR request, then in the Browser process you can handle the request using CEF API.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Hold Render Process until message recieved

Postby Albus » Tue Apr 03, 2018 2:46 am

magreenblatt wrote:Indeed, if you block the renderer process main thread you will not receive incoming messages. What are you trying to accomplish?

In JavaScript I call a nativ function (registered by me in the browser). This call is routed to the renderer process. But I have to execute it in the browser process. Therefore I send a message from the rednerer process to the browser process with all the information needed. Than I execute my code in the browser process and send a message with the result back to the renderer process. But because this all should be synchronus the renderer process has to wait until the browser process is ready and sends back the message with the answer.
If this had worked it would be the very best case. But if there is no possibility for this to work I have to make a solution with callback functions as a parameter of my nativ function. But synchronus function calls would be very much easier for our JavaScript development. And I don't want to use XHR for this would to much overhead.
Albus
 

Re: Hold Render Process until message recieved

Postby ndesktop » Tue Apr 03, 2018 5:54 am

High chances of deadlocks, if you ask me. There is a reason why synchronous XHR are deprecated for quite some time now.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: Hold Render Process until message recieved

Postby Albus » Tue Apr 03, 2018 8:19 am

I made it now synchonus with callback functions. But now I have an other problem with shredded variables and access violations. But I open a new topic for this.
Albus
 


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 27 guests