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

how to reuse TcpStream code from src/sys/windows/tcp.rs ? #578

Closed
Dushistov opened this Issue Mar 26, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@Dushistov
Copy link

Dushistov commented Mar 26, 2017

cc @alexcrichton @carllerche

I want to work with AF_BTH socket on windows OS,
to demonstrate what I am talking about here some code (blocking variant):

//create
let bt_socket: SOCKET = unsafe { socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM) };
//skip error handling
let mut sock_addr = SOCKADDR_BTH {
      addressFamily: AF_BTH as USHORT,
      btAddr: bt_addr.into(),
      serviceClassId: RFCOMM_PROTOCOL_UUID,
      port: BT_PORT_ANY,
};
let sock_addr_ptr: *mut SOCKADDR_BTH = &mut sock_addr;
let err = unsafe { connect(socket, sock_addr_ptr as *mut SOCKADDR, mem::size_of_val(sock_addr) };

As I understand comments from lib.rs and windows mod.rs I basically need not only use windows::Binding to imlement mio::Eventd, but also starts I/O with overlapped structures on readiness request, so basicaly copy/paste code from windows/tcp.rs and modify for my need, am I right?

If so, do you accept PR that generalize windows/tcp.rs to any SOCK_STREAM and allow some kind of user defined connect and socket creation functions?

@alexcrichton

This comment has been minimized.

Copy link
Contributor

alexcrichton commented Mar 27, 2017

I'd recommend taking a look at mio-named-pipes which are named pipes for mio, which you'll also likely want to mirror. In general though yes, you'll want to copy code from tcp.rs and adapt it as appropriate, it won't ever be publicly exposed from mio itself.

@Dushistov

This comment has been minimized.

Copy link
Author

Dushistov commented Mar 27, 2017

@alexcrichton I looked at mio-named-pipes, looks a lot of code duplication
with mio/sys/windows, do you have any plans for refactoring?

For example, why not just call in Binding::register_socket/register_handle
approapriate schedule functions?

@carllerche

This comment has been minimized.

Copy link
Owner

carllerche commented Mar 27, 2017

@alexcrichton

This comment has been minimized.

Copy link
Contributor

alexcrichton commented Mar 27, 2017

Currently no I don't plan on deduplicating, I'd personally prefer the freedom to change TCP bindings in mio itself and then at my leisure update other bindings. Exposing an API as a public interface would require everything to change all at once (and would make it very difficult to change)

@carllerche carllerche closed this Mar 27, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.