From dc44d1619a0fe4d6373eadcd2901940ea8ee0538 Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Fri, 5 May 2017 14:24:04 +0100 Subject: [PATCH] support for multiple bind addresses on the fast server --- lib/postal/fast_server/server.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/postal/fast_server/server.rb b/lib/postal/fast_server/server.rb index 5320792..3ed8861 100644 --- a/lib/postal/fast_server/server.rb +++ b/lib/postal/fast_server/server.rb @@ -13,12 +13,17 @@ module Postal Thread.abort_on_exception = true TrackCertificate - server_sockets = { - TCPServer.new(Postal.config.fast_server.bind_address, Postal.config.fast_server.ssl_port) => {:ssl => true}, - TCPServer.new(Postal.config.fast_server.bind_address, Postal.config.fast_server.port) => {:ssl => false}, - } - Postal.logger_for(:fast_server).info("Fast server started listening on HTTP (#{Postal.config.fast_server.bind_address}:#{Postal.config.fast_server.port})") - Postal.logger_for(:fast_server).info("Fast server started listening on HTTPS port (#{Postal.config.fast_server.bind_address}:#{Postal.config.fast_server.ssl_port})") + + bind_addresses = Postal.config.fast_server.bind_address + bind_addresses = [bind_addresses] unless bind_addresses.is_a?(Array) + + server_sockets = bind_addresses.each_with_object({}) do |bind_addr, sockets| + sockets[TCPServer.new(bind_addr, Postal.config.fast_server.port)] = {:ssl => false} + sockets[TCPServer.new(bind_addr, Postal.config.fast_server.ssl_port)] = {:ssl => true} + Postal.logger_for(:fast_server).info("Fast server started listening on HTTP (#{bind_addr}:#{Postal.config.fast_server.port})") + Postal.logger_for(:fast_server).info("Fast server started listening on HTTPS port (#{bind_addr}:#{Postal.config.fast_server.ssl_port})") + end + loop do client = nil ios = select(server_sockets.keys, nil, nil, 1)