diff options
author | Christopher Lenz <cmlenz@apache.org> | 2008-06-24 11:06:24 +0000 |
---|---|---|
committer | Christopher Lenz <cmlenz@apache.org> | 2008-06-24 11:06:24 +0000 |
commit | 561652bd7ee48748216a215ccbffa505bca63a0d (patch) | |
tree | 1315937b559f18ee77cc01ed932ac48acc26b6e6 /src/mochiweb/mochiweb_socket_server.erl | |
parent | d054aef0e2419db31d8277a051b54abdf6ee1d34 (diff) |
Updated MochiWeb in trunk to r82.
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@671125 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/mochiweb/mochiweb_socket_server.erl')
-rw-r--r-- | src/mochiweb/mochiweb_socket_server.erl | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/mochiweb/mochiweb_socket_server.erl b/src/mochiweb/mochiweb_socket_server.erl index 0d538ac9..d4853dad 100644 --- a/src/mochiweb/mochiweb_socket_server.erl +++ b/src/mochiweb/mochiweb_socket_server.erl @@ -96,6 +96,14 @@ start_server(State=#mochiweb_socket_server{name=Name}) -> gen_server:start_link(Name, ?MODULE, State, []) end. +ipv6_supported() -> + case (catch inet:getaddr("localhost", inet6)) of + {ok, _Addr} -> + true; + {error, _} -> + false + end. + init(State=#mochiweb_socket_server{ip=Ip, port=Port, backlog=Backlog}) -> process_flag(trap_exit, true), BaseOpts = [binary, @@ -106,11 +114,16 @@ init(State=#mochiweb_socket_server{ip=Ip, port=Port, backlog=Backlog}) -> {active, false}, {nodelay, true}], Opts = case Ip of - any -> - BaseOpts; - Ip -> - [{ip, Ip} | BaseOpts] - end, + any -> + case ipv6_supported() of % IPv4, and IPv6 if supported + true -> [inet, inet6 | BaseOpts]; + _ -> BaseOpts + end; + {_, _, _, _} -> % IPv4 + [inet, {ip, Ip} | BaseOpts]; + {_, _, _, _, _, _, _, _} -> % IPv6 + [inet6, {ip, Ip} | BaseOpts] + end, case gen_tcp_listen(Port, Opts, State) of {stop, eacces} -> case Port < 1024 of |