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

AF_UNIX support for Windows 10 #622

Open
ghost opened this issue Dec 30, 2020 · 1 comment
Open

AF_UNIX support for Windows 10 #622

ghost opened this issue Dec 30, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Dec 30, 2020

@cryptocode commented on May 27, 2018, 10:03 PM UTC:

The April update of Windows 10 includes AF_UNIX (domain sockets) support, and asio should support it.

BOOST_ASIO_HAS_LOCAL_SOCKETS would thus be true on recent Windows 10 hosts.

This issue was moved by chriskohlhoff from boostorg/asio#119.

@youyuanwu
Copy link

asio already works with Windows AF_UNIX. Example:
Server:

        std::filesystem::remove("my.sock");
        asio::io_context ioc{1};
        asio::local::stream_protocol::endpoint ep("my.sock");
        asio::local::stream_protocol::acceptor acceptor(ioc, ep, false/*reuse addr*/);
        asio::local::stream_protocol::socket socket(ioc);
        http_server(acceptor, socket); // see beast http server example
        ioc.run();

Client

        net::io_context ioc;
        net::local::stream_protocol::socket sock(ioc);
        sock.connect("my.sock");
        http::request<http::string_body> req{http::verb::get, "/count", 11};
        http::write(sock, req);

Caveats:

asio::local::stream_protocol::acceptor acceptor(ioc, ep, false/*reuse addr*/);
  • acceptor reuse addr must be false.
    If it is set to true, SO_REUSEADDR will be set on the socket using setsockopt, and winsock bind function will fail.
    SO_REUSEADDR set to true works on linux. But I don't think this opt applies to AF_UNIX, you can search online to see various discussion about SO_REUSEADDR and AF_UNIX.
  • You need to remove the socket file before open the socket(making the acceptor), in linux use ::unlink().

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

1 participant