Skip to content

enhance ability of embed with other event loop.#1651

Closed
churuxu wants to merge 1 commit into
libuv:v1.xfrom
churuxu:v1.x
Closed

enhance ability of embed with other event loop.#1651
churuxu wants to merge 1 commit into
libuv:v1.xfrom
churuxu:v1.x

Conversation

@churuxu

@churuxu churuxu commented Nov 24, 2017

Copy link
Copy Markdown

changes:

  1. add UV_LOOP_TIMEOUT_OBSERVER for uv_loop_option.
    observer function call when backend timeout of uv loop changed.
    for interrupt your self event loop.

  2. uv_backend_fd return iocp handle in windows.
    for call GetQueuedCompletionStatus your self.

  3. add uv_insert_overlapped_result windows specific function.
    for pass result of GetQueuedCompletionStatus to uv loop.


Example case for win32 gui application:
in main thread just run default win32 message loop.

while(GetMessage(&msg,NULL,0,0)){
  TranslateMessage(&msg);
  DispatchMessage(&msg);
}

create a window to handle uv events in it's WndProc.

if(msg == WM_UV_READY){
  if(lparam)uv_insert_overlapped_result(loop, (LPOVERLAPPED)lparam); 
  uv_run(loop, UV_RUN_NOWAIT);
}

create a thread to poll iocp events.

LPOVERLAPPED overlapped;
while(1){
  GetQueuedCompletionStatus(... overlapped, timeout_);
  SendMessage(hwnd, WM_UV_READY, 0, overlapped);  
}

in timeout observer function, interrupt GetQueuedCompletionStatus

void on_timeout_change(... timeout){
  timeout_ = timeout;
  PostQueuedCompletionStatus(iocp,0,0,NULL);
}
uv_loop_configure(loop, UV_LOOP_TIMEOUT_OBSERVER, on_timeout_change);

changes:
1. add UV_LOOP_TIMEOUT_OBSERVER for uv_loop_option.
  observer function call when backend timeout of uv loop changed.
  for interrupt your self event loop.

2. uv_backend_fd return iocp handle in windows.
  for call GetQueuedCompletionStatus your self.

3. add uv_insert_overlapped_result windows specific function.
  for pass result of GetQueuedCompletionStatus to uv loop.
@bnoordhuis

Copy link
Copy Markdown
Member

Thanks, but since this breaks ABI (changes sizeof(uv_loop_t)), it can't land in the stable branch.

Have you seen #1544 and #1568? Please read the discussions carefully; they both need some work but would they address your use case?

@churuxu

churuxu commented Nov 27, 2017

Copy link
Copy Markdown
Author

they are not address my use case.
I want to embed uv loop into win32 gui application (uv_run must in main thread).
do you have a better way? or can you support this use case in future version of libuv?

@bnoordhuis

Copy link
Copy Markdown
Member

@churuxu I'm going to close this out. Can you open an issue if you want to discuss options on how to make embedding easier for you in a way that is backwards compatible? Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants