Skip to content

Add uv_overlapped_t for custom IOCP integration (WIP)#1544

Closed
ambrop72 wants to merge 1 commit into
libuv:masterfrom
ambrop72:uv_overlapped_t
Closed

Add uv_overlapped_t for custom IOCP integration (WIP)#1544
ambrop72 wants to merge 1 commit into
libuv:masterfrom
ambrop72:uv_overlapped_t

Conversation

@ambrop72

Copy link
Copy Markdown

This is my first attempt to add support for integration of arbitrary handles with IOCP (issue #1541). It is slightly different from my initial proposal.

The uv_overlapped_t handle is used like this:

  • uv_overlapped_get_iocp is used to get the IOCP handle of the event loop.
  • uv_overlapped_get_overlapped is used to get the pointer to the OVERLAPPED structure.
  • uv_overlapped_start must be called after the application has submitted an I/O request (before the event loop next does the polling; else we crash sooner or later). This makes the uv_overlapped_t handle active, and uv_overlapped_start must not be called again before the callback is invoked.
  • When the completion arrives, the uv_overlapped_t handle becomes inactive and the callback is invoked.

uv_close on uv_overlapped_t behaves like this:

  • If inactive and the close callback is null, the handle is closed immediately.
  • If inactive and the close callback is not null, the handle is marked as closing and the close is completed asynchronously via the existing "endgame" mechanism that is in place.
  • If active, the close is completed asynchronously only after the completion arrives.

This is currently untested (but compiles).

@ambrop72

Copy link
Copy Markdown
Author

Hi,
This code as is works well for me with TAP-Windows both for sending and receiving frames. All there is left to do is add documentation. Can I expect this will be merged?

@bzoz

bzoz commented Sep 28, 2017

Copy link
Copy Markdown
Member

Is there anything similar that can be done on Linux? Some kind of uv_custom_t?

Comment thread src/win/overlapped.c
@@ -0,0 +1,115 @@
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick note: use that copyright text:

/* Copyright the libuv project contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

@ambrop72

Copy link
Copy Markdown
Author

@bzoz On Linux there is uv_poll_t which allows detecting when an arbitrary file descriptor is readable or writable, which is enough to integrate many types of I/O including TUN/TAP device. uv_poll_t exists on Windows too but is for sockets only not overlapped operations.

@bzoz

bzoz commented Oct 3, 2017

Copy link
Copy Markdown
Member

So, can maybe uv_poll_t be extended? I've took a quick look at uv_poll_s it looks like it could be used to hold everything that uv_overlapped_t needs, even without breaking v1.x ABI.

@ambrop72

ambrop72 commented Oct 9, 2017

Copy link
Copy Markdown
Author

Right, this can be merged into uv_poll_t, for example:

  • New init function uv_poll_init_overlapped (alongside existing uv_poll_init and uv_poll_init_socket).
  • Existing function uv_poll_start is the equivalent of current uv_overlapped_start.
  • Functions to get OVERLAPPED* and IOCP HANDLE are added: uv_poll_get_overlapped, uv_poll_get_iocp.
  • uv_poll_stop must not be called for uv_poll_t handles of overlapped kind (it cannot be implemented in any reasonable way due to IOCP design).

Can the persons with authority please comment on these proposals? Can I expect this feature to be merged? If so, should it be a new handle type as in the current pull request or should it be added to uv_poll_t?

@joshperry

Copy link
Copy Markdown

May be related to #484. We've been wanting something like this for node-serialport for a long time.

@ambrop72

ambrop72 commented Nov 6, 2017

Copy link
Copy Markdown
Author

@joshperry One should certainly be able to implement serial top on top of uv_overlapped_t. I am using this code for the TAP-Win32 driver and it works without issues. The application code is here: https://github.com/ambrop72/aipstack/tree/master/examples/tap_windows

Anyway I think that the architecture of libuv is a bit off in that different handle types are not easily composeable and reused internally. Ideally the core event loop implementation would only provide and know about the primitive event facilities, which are timers and whatever is the native IO notification mechanism on the platform (file descriptor readiness or IOCP). Everything else could be build on top of that (e.g. uv_loop_t shouldn't need to know about tcp, udp, filesystem, etc).

@stale

stale Bot commented Aug 10, 2019

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants