Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uv_open #200

Closed
txdv opened this issue Feb 11, 2015 · 7 comments
Closed

uv_open #200

txdv opened this issue Feb 11, 2015 · 7 comments

Comments

@txdv
Copy link
Contributor

txdv commented Feb 11, 2015

I was looking into the code and one thing stood out in my eyes: we have functions like uv_write and uv_fileno which basically accept any kind of handle and dependent on the type of it (which is a basically a variable in the struct) it determines what to do.

Yet we have multiple functions for opening an already existing file descriptor: uv_tcp_open, uv_udp_open.

The most annoying part IMO is that there is no uv_tty_open, even though the constructor of uv_tty_init requires a file descriptor. I think we could move the functionality of opening a file descriptor in a tty to open.

I think creating uv_open would make writing bindings easier, because currently it kinda is a lot of code.

@txdv
Copy link
Contributor Author

txdv commented Feb 11, 2015

Ok, after further investigation, the signatures are a bit different:

UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock);
UV_EXTERN int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock);
UV_EXTERN int uv_pipe_open(uv_pipe_t*, uv_file file);

On windows uv_os_sock_t is SOCKET. Don't know what to make of it.

@saghul
Copy link
Member

saghul commented Feb 12, 2015

This would indeed be nice, specially on Unix, there everything is a fd. On Windows, however, we have a problem, which I don't know how to solve elegantly. AFAIK all SOCKET and HANDLEs can be stored as 32bit integers, because even on 64bit Windows, handles only use the lest signifficant 32bits, but it sounds too much like a hack.

@txdv
Copy link
Contributor Author

txdv commented Feb 12, 2015

We could use IntPtr and cast to Int on unix only.

@saghul
Copy link
Member

saghul commented Feb 12, 2015

That's just reversing the hack :-S

@txdv
Copy link
Contributor Author

txdv commented Feb 12, 2015

But there is no possible way we loose precision that way

@saghul
Copy link
Member

saghul commented Feb 12, 2015

I still think we're trying to force it here. Not to mention intptr_t is a C99-ism, IIRC.

While I like the idea, I don't like how the implementation would result, so lets stick with the different functions we have for now.

@txdv
Copy link
Contributor Author

txdv commented Feb 12, 2015

I agree, this is the way C libs work

@txdv txdv closed this as completed Feb 12, 2015
gagern pushed a commit to gagern/libuv that referenced this issue Apr 7, 2015
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

No branches or pull requests

2 participants