diff options
| -rw-r--r-- | Makefile | 3 | ||||
| -rw-r--r-- | build.config | 3 | ||||
| -rw-r--r-- | erlang.mk | 295 | ||||
| -rw-r--r-- | src/rabbit.app.src | 6 | ||||
| -rw-r--r-- | src/rabbit_connection_sup.erl | 9 | ||||
| -rw-r--r-- | src/rabbit_vm.erl | 6 | ||||
| -rw-r--r-- | src/tcp_acceptor.erl | 105 | ||||
| -rw-r--r-- | src/tcp_acceptor_sup.erl | 43 | ||||
| -rw-r--r-- | src/tcp_listener.erl | 53 | ||||
| -rw-r--r-- | src/tcp_listener_sup.erl | 60 |
10 files changed, 261 insertions, 322 deletions
@@ -4,7 +4,8 @@ VERSION ?= $(call get_app_version,src/$(PROJECT).app.src) # Release artifacts are put in $(PACKAGES_DIR). PACKAGES_DIR ?= $(abspath PACKAGES) -DEPS = $(PLUGINS) +DEPS = ranch $(PLUGINS) +dep_ranch = git https://github.com/ninenines/ranch 1.2.0 define usage_xml_to_erl $(subst __,_,$(patsubst $(DOCS_DIR)/rabbitmq%.1.xml, src/rabbit_%_usage.erl, $(subst -,_,$(1)))) diff --git a/build.config b/build.config index 138af905ca..a741898ddf 100644 --- a/build.config +++ b/build.config @@ -38,3 +38,6 @@ plugins/xref # Plugins enhancing the functionality of other plugins. plugins/cover + +# Core modules which can use variables from plugins. +core/deps-tools @@ -16,7 +16,7 @@ ERLANG_MK_FILENAME := $(realpath $(lastword $(MAKEFILE_LIST))) -ERLANG_MK_VERSION = 1.2.0-845-gd330ec4-dirty +ERLANG_MK_VERSION = 1.2.0-849-g29268fc-dirty # Core configuration. @@ -196,8 +196,11 @@ ERLANG_MK_BUILD_DIR ?= .erlang.mk.build erlang-mk: git clone $(ERLANG_MK_REPO) $(ERLANG_MK_BUILD_DIR) +ifdef ERLANG_MK_COMMIT + cd $(ERLANG_MK_BUILD_DIR) && git checkout $(ERLANG_MK_COMMIT) +endif if [ -f $(ERLANG_MK_BUILD_CONFIG) ]; then cp $(ERLANG_MK_BUILD_CONFIG) $(ERLANG_MK_BUILD_DIR)/build.config; fi - cd $(ERLANG_MK_BUILD_DIR) && $(if $(ERLANG_MK_COMMIT),git checkout $(ERLANG_MK_COMMIT) &&) $(MAKE) + $(MAKE) -C $(ERLANG_MK_BUILD_DIR) cp $(ERLANG_MK_BUILD_DIR)/erlang.mk ./erlang.mk rm -rf $(ERLANG_MK_BUILD_DIR) @@ -433,7 +436,7 @@ pkg_bullet_name = bullet pkg_bullet_description = Simple, reliable, efficient streaming for Cowboy. pkg_bullet_homepage = http://ninenines.eu pkg_bullet_fetch = git -pkg_bullet_repo = https://github.com/extend/bullet +pkg_bullet_repo = https://github.com/ninenines/bullet pkg_bullet_commit = master PACKAGES += cache @@ -4018,7 +4021,7 @@ endif # Copyright (c) 2013-2015, Loïc Hoguin <essen@ninenines.eu> # This file is part of erlang.mk and subject to the terms of the ISC License. -.PHONY: fetch-deps list-deps distclean-deps +.PHONY: distclean-deps # Configuration. @@ -4066,29 +4069,6 @@ dep_verbose = $(dep_verbose_$(V)) # Core targets. ifneq ($(SKIP_DEPS),) -fetch-deps: -else -fetch-deps: $(ALL_DEPS_DIRS) -ifndef IS_APP - $(verbose) for dep in $(ALL_APPS_DIRS) ; do \ - $(MAKE) -C $$dep fetch-deps IS_APP=1 || exit $$?; \ - done -endif -ifneq ($(IS_DEP),1) - $(verbose) rm -f $(ERLANG_MK_TMP)/fetch-deps.log -endif - $(verbose) mkdir -p $(ERLANG_MK_TMP) - $(verbose) for dep in $(ALL_DEPS_DIRS) ; do \ - if ! grep -qs ^$$dep$$ $(ERLANG_MK_TMP)/fetch-deps.log; then \ - echo $$dep >> $(ERLANG_MK_TMP)/fetch-deps.log; \ - if [ -f $$dep/erlang.mk ]; then \ - $(MAKE) -C $$dep fetch-deps IS_DEP=1 || exit $$?; \ - fi \ - fi \ - done -endif - -ifneq ($(SKIP_DEPS),) deps:: else deps:: $(ALL_DEPS_DIRS) @@ -4116,37 +4096,6 @@ endif done endif -ERLANG_MK_RECURSIVE_DEPS_LIST = $(ERLANG_MK_TMP)/list-deps.log - -$(ERLANG_MK_RECURSIVE_DEPS_LIST): fetch-deps -ifneq ($(IS_DEP),1) - $(verbose) rm -f $(ERLANG_MK_TMP)/list-deps.log.orig -endif -ifndef IS_APP - $(verbose) for app in $(filter-out $(CURDIR),$(ALL_APPS_DIRS)); do \ - $(MAKE) -C "$$app" --no-print-directory \ - $(ERLANG_MK_RECURSIVE_DEPS_LIST) IS_APP=1 || :; \ - done -endif - $(verbose) for dep in $(filter-out $(CURDIR),$(ALL_DEPS_DIRS)); do \ - (test -f "$$dep/erlang.mk" && \ - $(MAKE) -C "$$dep" --no-print-directory \ - $(ERLANG_MK_RECURSIVE_DEPS_LIST) IS_DEP=1) || :; \ - done - $(verbose) for dep in $(DEPS); do \ - echo $(DEPS_DIR)/$$dep; \ - done >> $(ERLANG_MK_TMP)/list-deps.log.orig -ifndef IS_APP -ifneq ($(IS_DEP),1) - $(verbose) sort < $(ERLANG_MK_TMP)/list-deps.log.orig \ - | uniq > $(ERLANG_MK_TMP)/list-deps.log - $(verbose) rm -f $(ERLANG_MK_TMP)/list-deps.log.orig -endif -endif - -list-deps: $(ERLANG_MK_RECURSIVE_DEPS_LIST) - $(verbose) cat $(ERLANG_MK_TMP)/list-deps.log - # Deps related targets. # @todo rename GNUmakefile and makefile into Makefile first, if they exist @@ -4251,7 +4200,7 @@ define dep_autopatch_rebar.erl file:write_file("$(call core_native_path,$(DEPS_DIR)/$1/Makefile)", Text, [append]) end, Escape = fun (Text) -> - re:replace(Text, "\\\\$$$$", "\$$$$$$$$", [global, {return, list}]) + re:replace(Text, "\\\\$$", "\$$$$", [global, {return, list}]) end, Write("IGNORE_DEPS += edown eper eunit_formatters meck node_package " "rebar_lock_deps_plugin rebar_vsn_plugin reltool_util\n"), @@ -4374,10 +4323,10 @@ define dep_autopatch_rebar.erl Write("\npre-app::\n"), PatchHook = fun(Cmd) -> case Cmd of - "make -C" ++ Cmd1 -> "$$$$\(MAKE) -C" ++ Escape(Cmd1); - "gmake -C" ++ Cmd1 -> "$$$$\(MAKE) -C" ++ Escape(Cmd1); - "make " ++ Cmd1 -> "$$$$\(MAKE) -f Makefile.orig.mk " ++ Escape(Cmd1); - "gmake " ++ Cmd1 -> "$$$$\(MAKE) -f Makefile.orig.mk " ++ Escape(Cmd1); + "make -C" ++ Cmd1 -> "$$\(MAKE) -C" ++ Escape(Cmd1); + "gmake -C" ++ Cmd1 -> "$$\(MAKE) -C" ++ Escape(Cmd1); + "make " ++ Cmd1 -> "$$\(MAKE) -f Makefile.orig.mk " ++ Escape(Cmd1); + "gmake " ++ Cmd1 -> "$$\(MAKE) -f Makefile.orig.mk " ++ Escape(Cmd1); _ -> Escape(Cmd) end end, @@ -4389,10 +4338,10 @@ define dep_autopatch_rebar.erl {'get-deps', Cmd} -> Write("\npre-deps::\n\t" ++ PatchHook(Cmd) ++ "\n"); {compile, Cmd} -> - Write("\npre-app::\n\tCC=$$$$\(CC) " ++ PatchHook(Cmd) ++ "\n"); + Write("\npre-app::\n\tCC=$$\(CC) " ++ PatchHook(Cmd) ++ "\n"); {Regex, compile, Cmd} -> case rebar_utils:is_arch(Regex) of - true -> Write("\npre-app::\n\tCC=$$$$\(CC) " ++ PatchHook(Cmd) ++ "\n"); + true -> Write("\npre-app::\n\tCC=$$\(CC) " ++ PatchHook(Cmd) ++ "\n"); false -> ok end; _ -> ok @@ -4400,7 +4349,7 @@ define dep_autopatch_rebar.erl end end(), ShellToMk = fun(V) -> - re:replace(re:replace(V, "(\\\\$$$$)(\\\\w*)", "\\\\1(\\\\2)", [global]), + re:replace(re:replace(V, "(\\\\$$)(\\\\w*)", "\\\\1(\\\\2)", [global]), "-Werror\\\\b", "", [{return, list}, global]) end, PortSpecs = fun() -> @@ -4434,7 +4383,7 @@ define dep_autopatch_rebar.erl case PortSpecs of [] -> ok; _ -> - Write("\npre-app::\n\t$$$$\(MAKE) -f c_src/Makefile.erlang.mk\n"), + Write("\npre-app::\n\t$$\(MAKE) -f c_src/Makefile.erlang.mk\n"), PortSpecWrite(io_lib:format("ERL_CFLAGS = -finline-functions -Wall -fPIC -I ~s/erts-~s/include -I ~s\n", [code:root_dir(), erlang:system_info(version), code:lib_dir(erl_interface, include)])), PortSpecWrite(io_lib:format("ERL_LDFLAGS = -L ~s -lerl_interface -lei\n", @@ -4472,14 +4421,14 @@ define dep_autopatch_rebar.erl _ -> "" end, "\n\nall:: ", Output, "\n\n", - "%.o: %.c\n\t$$$$\(CC) -c -o $$$$\@ $$$$\< $$$$\(CFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n", - "%.o: %.C\n\t$$$$\(CXX) -c -o $$$$\@ $$$$\< $$$$\(CXXFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n", - "%.o: %.cc\n\t$$$$\(CXX) -c -o $$$$\@ $$$$\< $$$$\(CXXFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n", - "%.o: %.cpp\n\t$$$$\(CXX) -c -o $$$$\@ $$$$\< $$$$\(CXXFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n", + "%.o: %.c\n\t$$\(CC) -c -o $$\@ $$\< $$\(CFLAGS) $$\(ERL_CFLAGS) $$\(DRV_CFLAGS) $$\(EXE_CFLAGS)\n\n", + "%.o: %.C\n\t$$\(CXX) -c -o $$\@ $$\< $$\(CXXFLAGS) $$\(ERL_CFLAGS) $$\(DRV_CFLAGS) $$\(EXE_CFLAGS)\n\n", + "%.o: %.cc\n\t$$\(CXX) -c -o $$\@ $$\< $$\(CXXFLAGS) $$\(ERL_CFLAGS) $$\(DRV_CFLAGS) $$\(EXE_CFLAGS)\n\n", + "%.o: %.cpp\n\t$$\(CXX) -c -o $$\@ $$\< $$\(CXXFLAGS) $$\(ERL_CFLAGS) $$\(DRV_CFLAGS) $$\(EXE_CFLAGS)\n\n", [[Output, ": ", K, " = ", ShellToMk(V), "\n"] || {K, V} <- lists:reverse(MergeEnv(FilterEnv(Env)))], - Output, ": $$$$\(foreach ext,.c .C .cc .cpp,", - "$$$$\(patsubst %$$$$\(ext),%.o,$$$$\(filter %$$$$\(ext),$$$$\(wildcard", Input, "))))\n", - "\t$$$$\(CC) -o $$$$\@ $$$$\? $$$$\(LDFLAGS) $$$$\(ERL_LDFLAGS) $$$$\(DRV_LDFLAGS) $$$$\(EXE_LDFLAGS)", + Output, ": $$\(foreach ext,.c .C .cc .cpp,", + "$$\(patsubst %$$\(ext),%.o,$$\(filter %$$\(ext),$$\(wildcard", Input, "))))\n", + "\t$$\(CC) -o $$\@ $$\? $$\(LDFLAGS) $$\(ERL_LDFLAGS) $$\(DRV_LDFLAGS) $$\(EXE_LDFLAGS)", case filename:extension(Output) of [] -> "\n"; _ -> " -shared\n" @@ -4693,6 +4642,15 @@ distclean-deps: $(gen_verbose) rm -rf $(DEPS_DIR) endif +# Forward-declare variables used in core/deps-tools.mk. This is required +# in case plugins use them. + +ERLANG_MK_RECURSIVE_DEPS_LIST = $(ERLANG_MK_TMP)/list-deps.log +ERLANG_MK_RECURSIVE_DOC_DEPS_LIST = $(ERLANG_MK_TMP)/list-doc-deps.log +ERLANG_MK_RECURSIVE_REL_DEPS_LIST = $(ERLANG_MK_TMP)/list-rel-deps.log +ERLANG_MK_RECURSIVE_TEST_DEPS_LIST = $(ERLANG_MK_TMP)/list-test-deps.log +ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST = $(ERLANG_MK_TMP)/list-shell-deps.log + # External plugins. DEP_PLUGINS ?= @@ -5499,21 +5457,10 @@ endef # Plugin-specific targets. define render_template - $(verbose) echo "$${_$(1)}" > $(2) + $(shell mkdir -p $(dir $(2))) + $(file > $(2),$(call $(1))) endef -ifndef WS -ifdef SP -WS = $(subst a,,a $(wordlist 1,$(SP),a a a a a a a a a a a a a a a a a a a a)) -else -WS = $(tab) -endif -endif - -$(foreach template,$(filter bs_% tpl_%,$(.VARIABLES)), \ - $(eval _$(template) = $$(subst $$(tab),$$(WS),$$($(template)))) \ - $(eval export _$(template))) - bootstrap: ifneq ($(wildcard src/),) $(error Error: src/ directory already exists) @@ -5521,7 +5468,7 @@ endif $(eval p := $(PROJECT)) $(eval n := $(PROJECT)_sup) $(call render_template,bs_Makefile,Makefile) - $(verbose) mkdir src/ + $(verbose) mkdir -p src/ ifdef LEGACY $(call render_template,bs_appsrc,src/$(PROJECT).app.src) endif @@ -5534,7 +5481,7 @@ ifneq ($(wildcard src/),) endif $(eval p := $(PROJECT)) $(call render_template,bs_Makefile,Makefile) - $(verbose) mkdir src/ + $(verbose) mkdir -p src/ ifdef LEGACY $(call render_template,bs_appsrc_lib,src/$(PROJECT).app.src) endif @@ -5548,7 +5495,7 @@ ifneq ($(wildcard rel/),) endif $(eval p := $(PROJECT)) $(call render_template,bs_relx_config,relx.config) - $(verbose) mkdir rel/ + $(verbose) mkdir -p rel/ $(call render_template,bs_sys_config,rel/sys.config) $(call render_template,bs_vm_args,rel/vm.args) @@ -5799,10 +5746,6 @@ hello(_) -> erlang:nif_error({not_loaded, ?MODULE}). endef -$(foreach template,bs_c_nif bs_erl_nif, \ - $(eval _$(template) = $$(subst $$(tab),$$(WS),$$($(template)))) \ - $(eval export _$(template))) - new-nif: ifneq ($(wildcard $(C_SRC_DIR)/$n.c),) $(error Error: $(C_SRC_DIR)/$n.c already exists) @@ -6504,3 +6447,167 @@ cover-report: endif endif # ifneq ($(COVER_REPORT_DIR),) + +# Copyright (c) 2013-2015, Loïc Hoguin <essen@ninenines.eu> +# Copyright (c) 2015, Jean-Sébastien Pédron <jean-sebastien@rabbitmq.com> +# This file is part of erlang.mk and subject to the terms of the ISC License. + +# Fetch dependencies (without building them). + +.PHONY: fetch-deps fetch-doc-deps fetch-rel-deps fetch-test-deps \ + fetch-shell-deps + +ifneq ($(SKIP_DEPS),) +fetch-deps fetch-doc-deps fetch-rel-deps fetch-test-deps fetch-shell-deps: + @: +else +# By default, we fetch "normal" dependencies. They are also included no +# matter the type of requested dependencies. +# +# $(ALL_DEPS_DIRS) includes $(BUILD_DEPS). +fetch-deps: $(ALL_DEPS_DIRS) +fetch-doc-deps: $(ALL_DEPS_DIRS) $(ALL_DOC_DEPS_DIRS) +fetch-rel-deps: $(ALL_DEPS_DIRS) $(ALL_REL_DEPS_DIRS) +fetch-test-deps: $(ALL_DEPS_DIRS) $(ALL_TEST_DEPS_DIRS) +fetch-shell-deps: $(ALL_DEPS_DIRS) $(ALL_SHELL_DEPS_DIRS) + +# Allow to use fetch-deps and $(DEP_TYPES) to fetch multiple types of +# dependencies with a single target. +ifneq ($(IS_DEP),1) +ifneq ($(filter doc,$(DEP_TYPES)),) +fetch-deps: $(ALL_DOC_DEPS_DIRS) +endif +ifneq ($(filter rel,$(DEP_TYPES)),) +fetch-deps: $(ALL_REL_DEPS_DIRS) +endif +ifneq ($(filter test,$(DEP_TYPES)),) +fetch-deps: $(ALL_TEST_DEPS_DIRS) +endif +ifneq ($(filter shell,$(DEP_TYPES)),) +fetch-deps: $(ALL_SHELL_DEPS_DIRS) +endif +endif # ifneq ($(IS_DEP),1) + +fetch-deps fetch-doc-deps fetch-rel-deps fetch-test-deps fetch-shell-deps: +ifndef IS_APP + $(verbose) for dep in $(ALL_APPS_DIRS) ; do \ + $(MAKE) -C $$dep $@ IS_APP=1 || exit $$?; \ + done +endif +ifneq ($(IS_DEP),1) + $(verbose) rm -f $(ERLANG_MK_TMP)/$@.log +endif + $(verbose) mkdir -p $(ERLANG_MK_TMP) + $(verbose) for dep in $^ ; do \ + if ! grep -qs ^$$dep$$ $(ERLANG_MK_TMP)/$@.log; then \ + echo $$dep >> $(ERLANG_MK_TMP)/$@.log; \ + if grep -qs -E "^[[:blank:]]*include[[:blank:]]+(erlang\.mk|.*/erlang\.mk)$$" \ + $$dep/GNUmakefile $$dep/makefile $$dep/Makefile; then \ + $(MAKE) -C $$dep $@ IS_DEP=1 || exit $$?; \ + fi \ + fi \ + done +endif # ifneq ($(SKIP_DEPS),) + +# List dependencies recursively. + +.PHONY: list-deps list-doc-deps list-rel-deps list-test-deps \ + list-shell-deps + +ifneq ($(SKIP_DEPS),) +$(ERLANG_MK_RECURSIVE_DEPS_LIST) \ +$(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST) \ +$(ERLANG_MK_RECURSIVE_REL_DEPS_LIST) \ +$(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST) \ +$(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST): + $(verbose) :> $@ +else +LIST_DIRS = $(ALL_DEPS_DIRS) +LIST_DEPS = $(DEPS) + +$(ERLANG_MK_RECURSIVE_DEPS_LIST): fetch-deps + +ifneq ($(IS_DEP),1) +$(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST): LIST_DIRS += $(ALL_DOC_DEPS_DIRS) +$(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST): LIST_DEPS += $(DOC_DEPS) +endif +$(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST): fetch-doc-deps + +ifneq ($(IS_DEP),1) +$(ERLANG_MK_RECURSIVE_REL_DEPS_LIST): LIST_DIRS += $(ALL_REL_DEPS_DIRS) +$(ERLANG_MK_RECURSIVE_REL_DEPS_LIST): LIST_DEPS += $(REL_DEPS) +endif +$(ERLANG_MK_RECURSIVE_REL_DEPS_LIST): fetch-rel-deps + +ifneq ($(IS_DEP),1) +$(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST): LIST_DIRS += $(ALL_TEST_DEPS_DIRS) +$(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST): LIST_DEPS += $(TEST_DEPS) +endif +$(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST): fetch-test-deps + +ifneq ($(IS_DEP),1) +$(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST): LIST_DIRS += $(ALL_SHELL_DEPS_DIRS) +$(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST): LIST_DEPS += $(SHELL_DEPS) +endif +$(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST): fetch-shell-deps + +$(ERLANG_MK_RECURSIVE_DEPS_LIST) \ +$(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST) \ +$(ERLANG_MK_RECURSIVE_REL_DEPS_LIST) \ +$(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST) \ +$(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST): +ifneq ($(IS_DEP),1) + $(verbose) rm -f $@.orig +endif +ifndef IS_APP + $(verbose) for app in $(filter-out $(CURDIR),$(ALL_APPS_DIRS)); do \ + $(MAKE) -C "$$app" --no-print-directory $@ IS_APP=1 || :; \ + done +endif + $(verbose) for dep in $(filter-out $(CURDIR),$(LIST_DIRS)); do \ + if grep -qs -E "^[[:blank:]]*include[[:blank:]]+(erlang\.mk|.*/erlang\.mk)$$" \ + $$dep/GNUmakefile $$dep/makefile $$dep/Makefile; then \ + $(MAKE) -C "$$dep" --no-print-directory $@ IS_DEP=1; \ + fi; \ + done + $(verbose) for dep in $(LIST_DEPS); do \ + echo $(DEPS_DIR)/$$dep; \ + done >> $@.orig +ifndef IS_APP +ifneq ($(IS_DEP),1) + $(verbose) sort < $@.orig | uniq > $@ + $(verbose) rm -f $@.orig +endif +endif +endif # ifneq ($(SKIP_DEPS),) + +ifneq ($(SKIP_DEPS),) +list-deps list-doc-deps list-rel-deps list-test-deps list-shell-deps: + @: +else +list-deps: $(ERLANG_MK_RECURSIVE_DEPS_LIST) +list-doc-deps: $(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST) +list-rel-deps: $(ERLANG_MK_RECURSIVE_REL_DEPS_LIST) +list-test-deps: $(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST) +list-shell-deps: $(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST) + +# Allow to use fetch-deps and $(DEP_TYPES) to fetch multiple types of +# dependencies with a single target. +ifneq ($(IS_DEP),1) +ifneq ($(filter doc,$(DEP_TYPES)),) +list-deps: $(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST) +endif +ifneq ($(filter rel,$(DEP_TYPES)),) +list-deps: $(ERLANG_MK_RECURSIVE_REL_DEPS_LIST) +endif +ifneq ($(filter test,$(DEP_TYPES)),) +list-deps: $(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST) +endif +ifneq ($(filter shell,$(DEP_TYPES)),) +list-deps: $(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST) +endif +endif + +list-deps list-doc-deps list-rel-deps list-test-deps list-shell-deps: + $(verbose) cat $^ | sort | uniq +endif # ifneq ($(SKIP_DEPS),) diff --git a/src/rabbit.app.src b/src/rabbit.app.src index fe9b1635ea..ab25c9e089 100644 --- a/src/rabbit.app.src +++ b/src/rabbit.app.src @@ -8,7 +8,6 @@ rabbit_node_monitor, rabbit_router, rabbit_sup, - rabbit_tcp_client_sup, rabbit_direct_client_sup]}, {applications, [kernel, stdlib, sasl, mnesia, os_mon, xmerl]}, %% we also depend on crypto, public_key and ssl but they shouldn't be @@ -57,10 +56,7 @@ {reverse_dns_lookups, false}, {cluster_partition_handling, ignore}, {cluster_keepalive_interval, 10000}, - {tcp_listen_options, [binary, - {packet, raw}, - {reuseaddr, true}, - {backlog, 128}, + {tcp_listen_options, [{backlog, 128}, {nodelay, true}, {linger, {true, 0}}, {exit_on_close, false}]}, diff --git a/src/rabbit_connection_sup.erl b/src/rabbit_connection_sup.erl index 982608556a..a64a2217da 100644 --- a/src/rabbit_connection_sup.erl +++ b/src/rabbit_connection_sup.erl @@ -17,8 +17,9 @@ -module(rabbit_connection_sup). -behaviour(supervisor2). +-behaviour(ranch_protocol). --export([start_link/0, reader/1]). +-export([start_link/4, reader/1]). -export([init/1]). @@ -28,14 +29,14 @@ -ifdef(use_specs). --spec(start_link/0 :: () -> {'ok', pid(), pid()}). +-spec(start_link/4 :: (any(), rabbit_net:socket(), module(), any()) -> {'ok', pid(), pid()}). -spec(reader/1 :: (pid()) -> pid()). -endif. %%-------------------------------------------------------------------------- -start_link() -> +start_link(Ref, Sock, _Transport, _Opts) -> {ok, SupPid} = supervisor2:start_link(?MODULE, []), %% We need to get channels in the hierarchy here so they get shut %% down after the reader, so the reader gets a chance to terminate @@ -55,7 +56,7 @@ start_link() -> {ok, ReaderPid} = supervisor2:start_child( SupPid, - {reader, {rabbit_reader, start_link, [HelperSup]}, + {reader, {rabbit_reader, start_link, [HelperSup, Ref, Sock]}, intrinsic, ?MAX_WAIT, worker, [rabbit_reader]}), {ok, SupPid, ReaderPid}. diff --git a/src/rabbit_vm.erl b/src/rabbit_vm.erl index 534a8883e1..4146eeb447 100644 --- a/src/rabbit_vm.erl +++ b/src/rabbit_vm.erl @@ -134,7 +134,11 @@ interesting_sups0() -> PluginProcs = plugin_sups(), [MsgIndexProcs, MgmtDbProcs, PluginProcs]. -conn_sups() -> [rabbit_tcp_client_sup, ssl_connection_sup, amqp_sup]. +%% @todo I have doubts about this ssl_connection_sup and the +%% amqp_sup. They don't seem to exist anywhere. +%% @todo We probably need to put the equivalent process here +%% (the one our Ranch supervisor is under). +conn_sups() -> [ssl_connection_sup, amqp_sup]. conn_sups(With) -> [{Sup, With} || Sup <- conn_sups()]. distinguishers() -> [{rabbit_amqqueue_sup_sup, fun queue_type/1} | diff --git a/src/tcp_acceptor.erl b/src/tcp_acceptor.erl deleted file mode 100644 index 75f216c3dd..0000000000 --- a/src/tcp_acceptor.erl +++ /dev/null @@ -1,105 +0,0 @@ -%% The contents of this file are subject to the Mozilla Public License -%% Version 1.1 (the "License"); you may not use this file except in -%% compliance with the License. You may obtain a copy of the License -%% at http://www.mozilla.org/MPL/ -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and -%% limitations under the License. -%% -%% The Original Code is RabbitMQ. -%% -%% The Initial Developer of the Original Code is GoPivotal, Inc. -%% Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved. -%% - --module(tcp_acceptor). - --behaviour(gen_server). - --export([start_link/2]). - --export([init/1, handle_call/3, handle_cast/2, handle_info/2, - terminate/2, code_change/3]). - --record(state, {callback, sock, ref}). - -%%-------------------------------------------------------------------- - -start_link(Callback, LSock) -> - gen_server:start_link(?MODULE, {Callback, LSock}, []). - -%%-------------------------------------------------------------------- - -init({Callback, LSock}) -> - gen_server:cast(self(), accept), - {ok, #state{callback=Callback, sock=LSock}}. - -handle_call(_Request, _From, State) -> - {noreply, State}. - -handle_cast(accept, State) -> - ok = file_handle_cache:obtain(), - accept(State); - -handle_cast(_Msg, State) -> - {noreply, State}. - -handle_info({inet_async, LSock, Ref, {ok, Sock}}, - State = #state{callback={M,F,A}, sock=LSock, ref=Ref}) -> - - %% patch up the socket so it looks like one we got from - %% gen_tcp:accept/1 - {ok, Mod} = inet_db:lookup_socket(LSock), - inet_db:register_socket(Sock, Mod), - - %% handle - case tune_buffer_size(Sock) of - ok -> file_handle_cache:transfer( - apply(M, F, A ++ [Sock])), - ok = file_handle_cache:obtain(); - {error, enotconn} -> catch port_close(Sock); - {error, Err} -> {ok, {IPAddress, Port}} = inet:sockname(LSock), - error_logger:error_msg( - "failed to tune buffer size of " - "connection accepted on ~s:~p - ~s~n", - [rabbit_misc:ntoab(IPAddress), Port, - rabbit_misc:format_inet_error(Err)]), - catch port_close(Sock) - end, - - %% accept more - accept(State); - -handle_info({inet_async, LSock, Ref, {error, Reason}}, - State=#state{sock=LSock, ref=Ref}) -> - case Reason of - closed -> {stop, normal, State}; %% listening socket closed - econnaborted -> accept(State); %% client sent RST before we accepted - _ -> {stop, {accept_failed, Reason}, State} - end; - -handle_info(_Info, State) -> - {noreply, State}. - -terminate(_Reason, _State) -> - ok. - -code_change(_OldVsn, State, _Extra) -> - {ok, State}. - -%%-------------------------------------------------------------------- - -accept(State = #state{sock=LSock}) -> - case prim_inet:async_accept(LSock, -1) of - {ok, Ref} -> {noreply, State#state{ref=Ref}}; - Error -> {stop, {cannot_accept, Error}, State} - end. - -tune_buffer_size(Sock) -> - case inet:getopts(Sock, [sndbuf, recbuf, buffer]) of - {ok, BufSizes} -> BufSz = lists:max([Sz || {_Opt, Sz} <- BufSizes]), - inet:setopts(Sock, [{buffer, BufSz}]); - Error -> Error - end. diff --git a/src/tcp_acceptor_sup.erl b/src/tcp_acceptor_sup.erl deleted file mode 100644 index 22c886e0ab..0000000000 --- a/src/tcp_acceptor_sup.erl +++ /dev/null @@ -1,43 +0,0 @@ -%% The contents of this file are subject to the Mozilla Public License -%% Version 1.1 (the "License"); you may not use this file except in -%% compliance with the License. You may obtain a copy of the License -%% at http://www.mozilla.org/MPL/ -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and -%% limitations under the License. -%% -%% The Original Code is RabbitMQ. -%% -%% The Initial Developer of the Original Code is GoPivotal, Inc. -%% Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved. -%% - --module(tcp_acceptor_sup). - --behaviour(supervisor). - --export([start_link/2]). - --export([init/1]). - -%%---------------------------------------------------------------------------- - --ifdef(use_specs). - --type(mfargs() :: {atom(), atom(), [any()]}). - --spec(start_link/2 :: (atom(), mfargs()) -> rabbit_types:ok_pid_or_error()). - --endif. - -%%---------------------------------------------------------------------------- - -start_link(Name, Callback) -> - supervisor:start_link({local,Name}, ?MODULE, Callback). - -init(Callback) -> - {ok, {{simple_one_for_one, 10, 10}, - [{tcp_acceptor, {tcp_acceptor, start_link, [Callback]}, - transient, brutal_kill, worker, [tcp_acceptor]}]}}. diff --git a/src/tcp_listener.erl b/src/tcp_listener.erl index 307249af09..571622c80d 100644 --- a/src/tcp_listener.erl +++ b/src/tcp_listener.erl @@ -18,12 +18,12 @@ -behaviour(gen_server). --export([start_link/8]). +-export([start_link/5]). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). --record(state, {sock, on_startup, on_shutdown, label}). +-record(state, {on_startup, on_shutdown, label, ip, port}). %%---------------------------------------------------------------------------- @@ -31,52 +31,31 @@ -type(mfargs() :: {atom(), atom(), [any()]}). --spec(start_link/8 :: - (inet:ip_address(), inet:port_number(), [gen_tcp:listen_option()], - integer(), atom(), mfargs(), mfargs(), string()) -> +-spec(start_link/5 :: + (inet:ip_address(), inet:port_number(), + mfargs(), mfargs(), string()) -> rabbit_types:ok_pid_or_error()). -endif. %%-------------------------------------------------------------------- -start_link(IPAddress, Port, SocketOpts, - ConcurrentAcceptorCount, AcceptorSup, +start_link(IPAddress, Port, OnStartup, OnShutdown, Label) -> gen_server:start_link( - ?MODULE, {IPAddress, Port, SocketOpts, - ConcurrentAcceptorCount, AcceptorSup, + ?MODULE, {IPAddress, Port, OnStartup, OnShutdown, Label}, []). %%-------------------------------------------------------------------- -init({IPAddress, Port, SocketOpts, - ConcurrentAcceptorCount, AcceptorSup, - {M,F,A} = OnStartup, OnShutdown, Label}) -> +init({IPAddress, Port, {M,F,A} = OnStartup, OnShutdown, Label}) -> process_flag(trap_exit, true), - case gen_tcp:listen(Port, SocketOpts ++ [{ip, IPAddress}, - {active, false}]) of - {ok, LSock} -> - lists:foreach(fun (_) -> - {ok, _APid} = supervisor:start_child( - AcceptorSup, [LSock]) - end, - lists:duplicate(ConcurrentAcceptorCount, dummy)), - {ok, {LIPAddress, LPort}} = inet:sockname(LSock), - error_logger:info_msg( - "started ~s on ~s:~p~n", - [Label, rabbit_misc:ntoab(LIPAddress), LPort]), - apply(M, F, A ++ [IPAddress, Port]), - {ok, #state{sock = LSock, - on_startup = OnStartup, on_shutdown = OnShutdown, - label = Label}}; - {error, Reason} -> - error_logger:error_msg( - "failed to start ~s on ~s:~p - ~p (~s)~n", - [Label, rabbit_misc:ntoab(IPAddress), Port, - Reason, inet:format_error(Reason)]), - {stop, {cannot_listen, IPAddress, Port, Reason}} - end. + error_logger:info_msg( + "started ~s on ~s:~p~n", + [Label, rabbit_misc:ntoab(IPAddress), Port]), + apply(M, F, A ++ [IPAddress, Port]), + {ok, #state{on_startup = OnStartup, on_shutdown = OnShutdown, + label = Label, ip=IPAddress, port=Port}}. handle_call(_Request, _From, State) -> {noreply, State}. @@ -87,9 +66,7 @@ handle_cast(_Msg, State) -> handle_info(_Info, State) -> {noreply, State}. -terminate(_Reason, #state{sock=LSock, on_shutdown = {M,F,A}, label=Label}) -> - {ok, {IPAddress, Port}} = inet:sockname(LSock), - gen_tcp:close(LSock), +terminate(_Reason, #state{on_shutdown = {M,F,A}, label=Label, ip=IPAddress, port=Port}) -> error_logger:info_msg("stopped ~s on ~s:~p~n", [Label, rabbit_misc:ntoab(IPAddress), Port]), apply(M, F, A ++ [IPAddress, Port]). diff --git a/src/tcp_listener_sup.erl b/src/tcp_listener_sup.erl index 94bdecc28c..54da154d8d 100644 --- a/src/tcp_listener_sup.erl +++ b/src/tcp_listener_sup.erl @@ -18,7 +18,7 @@ -behaviour(supervisor). --export([start_link/7, start_link/8]). +-export([start_link/9, start_link/10]). -export([init/1]). @@ -28,43 +28,41 @@ -type(mfargs() :: {atom(), atom(), [any()]}). --spec(start_link/7 :: - (inet:ip_address(), inet:port_number(), [gen_tcp:listen_option()], - mfargs(), mfargs(), mfargs(), string()) -> +-spec(start_link/9 :: + (inet:ip_address(), inet:port_number(), module(), [gen_tcp:listen_option()], + module(), any(), mfargs(), mfargs(), string()) -> rabbit_types:ok_pid_or_error()). --spec(start_link/8 :: - (inet:ip_address(), inet:port_number(), [gen_tcp:listen_option()], - mfargs(), mfargs(), mfargs(), integer(), string()) -> +-spec(start_link/10 :: + (inet:ip_address(), inet:port_number(), module(), [gen_tcp:listen_option()], + module(), any(), mfargs(), mfargs(), integer(), string()) -> rabbit_types:ok_pid_or_error()). -endif. %%---------------------------------------------------------------------------- -start_link(IPAddress, Port, SocketOpts, OnStartup, OnShutdown, - AcceptCallback, Label) -> - start_link(IPAddress, Port, SocketOpts, OnStartup, OnShutdown, - AcceptCallback, 1, Label). +start_link(IPAddress, Port, Transport, SocketOpts, ProtoSup, ProtoOpts, OnStartup, OnShutdown, + Label) -> + start_link(IPAddress, Port, Transport, SocketOpts, ProtoSup, ProtoOpts, OnStartup, OnShutdown, + 1, Label). -start_link(IPAddress, Port, SocketOpts, OnStartup, OnShutdown, - AcceptCallback, ConcurrentAcceptorCount, Label) -> +start_link(IPAddress, Port, Transport, SocketOpts, ProtoSup, ProtoOpts, OnStartup, OnShutdown, + ConcurrentAcceptorCount, Label) -> supervisor:start_link( - ?MODULE, {IPAddress, Port, SocketOpts, OnStartup, OnShutdown, - AcceptCallback, ConcurrentAcceptorCount, Label}). + ?MODULE, {IPAddress, Port, Transport, SocketOpts, ProtoSup, ProtoOpts, OnStartup, OnShutdown, + ConcurrentAcceptorCount, Label}). -init({IPAddress, Port, SocketOpts, OnStartup, OnShutdown, - AcceptCallback, ConcurrentAcceptorCount, Label}) -> - %% This is gross. The tcp_listener needs to know about the - %% tcp_acceptor_sup, and the only way I can think of accomplishing - %% that without jumping through hoops is to register the - %% tcp_acceptor_sup. - Name = rabbit_misc:tcp_name(tcp_acceptor_sup, IPAddress, Port), - {ok, {{one_for_all, 10, 10}, - [{tcp_acceptor_sup, {tcp_acceptor_sup, start_link, - [Name, AcceptCallback]}, - transient, infinity, supervisor, [tcp_acceptor_sup]}, - {tcp_listener, {tcp_listener, start_link, - [IPAddress, Port, SocketOpts, - ConcurrentAcceptorCount, Name, - OnStartup, OnShutdown, Label]}, - transient, 16#ffffffff, worker, [tcp_listener]}]}}. +init({IPAddress, Port, Transport, SocketOpts, ProtoSup, ProtoOpts, OnStartup, OnShutdown, + ConcurrentAcceptorCount, Label}) -> + {ok, AckTimeout} = application:get_env(rabbit, ssl_handshake_timeout), + {ok, {{one_for_all, 10, 10}, [ + ranch:child_spec({acceptor, IPAddress, Port}, ConcurrentAcceptorCount, + Transport, [{port, Port}, {ip, IPAddress}, + {max_connections, infinity}, + {ack_timeout, AckTimeout}, + {connection_type, supervisor}|SocketOpts], + ProtoSup, ProtoOpts), + {tcp_listener, {tcp_listener, start_link, + [IPAddress, Port, + OnStartup, OnShutdown, Label]}, + transient, 16#ffffffff, worker, [tcp_listener]}]}}. |
