Skip to content
This repository was archived by the owner on May 4, 2018. It is now read-only.

Add uv_device_t as stream on windows and linux, handle device I/O asyncly.#1580

Closed
zhaozg wants to merge 1 commit into
joyent:masterfrom
zhaozg:master
Closed

Add uv_device_t as stream on windows and linux, handle device I/O asyncly.#1580
zhaozg wants to merge 1 commit into
joyent:masterfrom
zhaozg:master

Conversation

@zhaozg

@zhaozg zhaozg commented Nov 13, 2014

Copy link
Copy Markdown

I'm a multi-language programmer, but not family with english, so maybe trouble with options. libuv is a good i/o framework, and easy to extent, I hope persist on it to do my work.

When I want to do r/w device on windows, I try filesystem api, it works for device handle, but not fit my needs. I need a real stream, I try wrap handle as pipe, and fail to work. When I study TTY and TCP, I realize that it not hard to implication a device type stream, because just file operation with overlapped, even simpler than other stream types.
When I finish my job on windows, i realize libUV is born for linux, simple to add a device type, so i did it.

There are only three type related api.

UV_EXTERN int uv_device_init(uv_loop_t* handle, uv_device_t* device,  const char* path, int flags);
UV_EXTERN int uv_device_ioctl(uv_device_t* device, int cmd, uv_ioargs_t* args);

uv_device_init will init and create a uv_deive_t, path should be '/dev/??' on linux or ".\Global???" on windows.
flags should be O_RDONLY,O_WRONLY or O_RDWR.

uv_device_ioctl will set or get device paramater, arg is relative with OS platform, return >=0 for success, detail please see header file.

because not test widely, so maybe have bugs, please attention.

Happy for do something for libUV.

@Nodejs-Jenkins Nodejs-Jenkins changed the title Add uv_device_t as stream on windows and linux, handle device I/O asyncly. Add uv_device_t as stream on windows and linux, handle device I/O asyncly. Nov 13, 2014
Comment thread src/win/device.c Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My experience with windows has been that you get called back even if the write is synchronous so you can safely ignore "returned immediately" scenarios.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It could be, if SetFileCompletionNotificationModes had been used.

But yes by default IOCP reports all succesful operations, even if they completed synchronously. So that looks like it needs to be fixed here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@cjdelisle

Copy link
Copy Markdown
Contributor

In general it looks like it will work for my use case, I'm still (of course) favorable to my own patch, in this case because it's fewer lines of code, but if this is code which I do not maintain, I'm happy with that so +1 in theory. If you feel like patching https://github.com/cjdelisle/cjdns/blob/master/interface/tuntap/windows/TAPInterface.c to work with your version then I'll really love you :)

@saghul

saghul commented Nov 13, 2014

Copy link
Copy Markdown
Contributor

Before getting into reviewing any code, I'd like to hear some general thoughts from @indutny, @bnoordhuis and @piscisaureus.

The approach taken here looks clean and nice to me, if that's enough for people wanting to use serial devices (for example) not to (ab)use uv_fs_open, I'm all in :-)

Comment thread include/uv-win.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why is this needed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This define device private field, for device handle, and read data buffer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see you no longer malloc your own buffer, good! Can you please rename this to read_buffer?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

good

@saghul

saghul commented Nov 14, 2014

Copy link
Copy Markdown
Contributor

Thanks @zhaozg! I did an initial review of the code (I didn't cover it all yet though).

Comment thread include/uv.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This one is inconsistent with the other _open functions. Maybe we should remove it and open the device in _init? That's what uv_tty_init does, for example.

@cjdelisle

Copy link
Copy Markdown
Contributor

Without having really followed this conversation except to periodically sweep the mess of mail out of my inbox, I thought perhaps you would enjoy reading parkinson's law :)

@saghul

saghul commented Nov 18, 2014

Copy link
Copy Markdown
Contributor

@cjdelisle :-)

Comment thread src/unix/device.c Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Return -EINVAL instead of asserting.

@zhaozg

zhaozg commented Nov 29, 2014

Copy link
Copy Markdown
Author

@saghul I should make a new RP to libuv/libuv?

@saghul

saghul commented Nov 29, 2014

Copy link
Copy Markdown
Contributor

If you don't mind, that would be great!
On Nov 29, 2014 5:21 AM, "George Zhao" notifications@github.com wrote:

@saghul https://github.com/saghul I should make a new RP to libuv/libuv?


Reply to this email directly or view it on GitHub
#1580 (comment).

@zhaozg

zhaozg commented Nov 29, 2014

Copy link
Copy Markdown
Author

Close this RP, because replaced with libuv/libuv#19.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants