[asio-users] How to use ip::v6_only with tcp::acceptor?
Brought to you by:
chris_kohlhoff
|
From: Asbjørn <lo...@gm...> - 2011-03-25 02:45:19
|
Hi,
I'm fairly new to asio and I tried to modify some server code to handle
ipv6 as well. The code should run on win/linux/osx and thus the easiest
way seems to be to enable the v6_flag and launch two listening threads,
one for ipv4 and one for ipv6.
I'm having some difficulty understanding how to enable the v6_only flag
with tcp:acceptor, which the current code uses. I tried setting it on
the acceptor but that failed.
If there is alternative to the acceptor that is ok, the main feature I
need is to be able to use a stream, and accept connections in a loop as
shown below (server can only handle one client at a time).
I'm using asio from Boost 1.43.
My listening thread code looks like this:
boost::asio::io_service io_service;
tcp::endpoint endpoint(ipversion == 4 ? tcp::v4() : tcp::v6(), listenPort);
tcp::acceptor acceptor(io_service, endpoint);
while (server->signal == SIG_NONE) {
tcp::iostream stream;
acceptor.accept(*stream.rdbuf());
... process request using stream
}
Any help is much appreciated.
Cheers
- Asbjørn
|