Просмотр исходного кода

Add 'listener.<proto>.<name>.reuseaddr' option

Feng Lee 8 лет назад
Родитель
Сommit
f70bf23440
2 измененных файлов с 75 добавлено и 24 удалено
  1. 48 23
      etc/emq.conf
  2. 27 1
      priv/emq.schema

+ 48 - 23
etc/emq.conf

@@ -704,6 +704,11 @@ listener.tcp.external.tune_buffer = on
 ## Value: true | false
 ## Value: true | false
 listener.tcp.external.nodelay = true
 listener.tcp.external.nodelay = true
 
 
+## The SO_REUSEADDR flag for TCP listener.
+##
+## Value: true | false
+listener.tcp.external.reuseaddr = true
+
 ##--------------------------------------------------------------------
 ##--------------------------------------------------------------------
 ## Internal TCP Listener for MQTT Protocol
 ## Internal TCP Listener for MQTT Protocol
 
 
@@ -800,6 +805,11 @@ listener.tcp.internal.tune_buffer = on
 ## Value: true | false
 ## Value: true | false
 listener.tcp.internal.nodelay = false
 listener.tcp.internal.nodelay = false
 
 
+## The SO_REUSEADDR flag for MQTT/TCP Listener.
+##
+## Value: true | false
+listener.tcp.internal.reuseaddr = true
+
 ##--------------------------------------------------------------------
 ##--------------------------------------------------------------------
 ## MQTT/SSL - External SSL Listener for MQTT Protocol
 ## MQTT/SSL - External SSL Listener for MQTT Protocol
 
 
@@ -1029,10 +1039,15 @@ listener.ssl.external.certfile = {{ platform_etc_dir }}/certs/cert.pem
 ## Value: true | false
 ## Value: true | false
 ## listener.ssl.external.nodelay = true
 ## listener.ssl.external.nodelay = true
 
 
+## The SO_REUSEADDR flag for MQTT/SSL Listener.
+##
+## Value: true | false
+listener.ssl.external.reuseaddr = true
+
 ##--------------------------------------------------------------------
 ##--------------------------------------------------------------------
 ## External WebSocket Listener for MQTT Protocol
 ## External WebSocket Listener for MQTT Protocol
 
 
-## listener.ws.<name> is the IP address and port that the MQTT/Websocket
+## listener.ws.<name> is the IP address and port that the MQTT/WebSocket
 ## listener will bind.
 ## listener will bind.
 ##
 ##
 ## Value: IP:Port | Port
 ## Value: IP:Port | Port
@@ -1040,29 +1055,29 @@ listener.ssl.external.certfile = {{ platform_etc_dir }}/certs/cert.pem
 ## Examples: 8083, 127.0.0.1:8083, ::1:8083
 ## Examples: 8083, 127.0.0.1:8083, ::1:8083
 listener.ws.external = 8083
 listener.ws.external = 8083
 
 
-## The acceptor pool for external MQTT/Websocket listener.
+## The acceptor pool for external MQTT/WebSocket listener.
 ##
 ##
 ## Value: Number
 ## Value: Number
 listener.ws.external.acceptors = 4
 listener.ws.external.acceptors = 4
 
 
-## Maximum number of concurrent MQTT/Websocket connections.
+## Maximum number of concurrent MQTT/WebSocket connections.
 ##
 ##
 ## Value: Number
 ## Value: Number
 listener.ws.external.max_clients = 102400
 listener.ws.external.max_clients = 102400
 
 
-## TODO: Zone of the external MQTT/Websocket listener belonged to.
+## TODO: Zone of the external MQTT/WebSocket listener belonged to.
 ##
 ##
 ## Value: String
 ## Value: String
 ## listener.ws.external.zone = external
 ## listener.ws.external.zone = external
 
 
-## Mountpoint of the MQTT/Websocket Listener.
+## Mountpoint of the MQTT/WebSocket Listener.
 ##
 ##
 ## See: listener.tcp.<name>.mountpoint
 ## See: listener.tcp.<name>.mountpoint
 ##
 ##
 ## Value: String
 ## Value: String
 ## listener.ws.external.mountpoint = external/
 ## listener.ws.external.mountpoint = external/
 
 
-## The access control for the MQTT/Websocket listener.
+## The access control for the MQTT/WebSocket listener.
 ##
 ##
 ## See: listener.tcp.<name>.access
 ## See: listener.tcp.<name>.access
 ##
 ##
@@ -1084,35 +1099,35 @@ listener.ws.external.access.1 = allow all
 ## Value: Duration
 ## Value: Duration
 ## listener.ws.external.proxy_protocol_timeout = 3s
 ## listener.ws.external.proxy_protocol_timeout = 3s
 
 
-## The TCP backlog of external MQTT/Websocket Listener.
+## The TCP backlog of external MQTT/WebSocket Listener.
 ##
 ##
 ## See: listener.tcp.<name>.backlog
 ## See: listener.tcp.<name>.backlog
 ##
 ##
 ## Value: Number >= 0
 ## Value: Number >= 0
 listener.ws.external.backlog = 1024
 listener.ws.external.backlog = 1024
 
 
-## The TCP send timeout for external MQTT/Websocket connections.
+## The TCP send timeout for external MQTT/WebSocket connections.
 ##
 ##
 ## See: listener.tcp.<name>.send_timeout
 ## See: listener.tcp.<name>.send_timeout
 ##
 ##
 ## Value: Duration
 ## Value: Duration
 listener.ws.external.send_timeout = 15s
 listener.ws.external.send_timeout = 15s
 
 
-## Close the MQTT/Websocket connection if send timeout.
+## Close the MQTT/WebSocket connection if send timeout.
 ##
 ##
 ## See: listener.tcp.<name>.send_timeout_close
 ## See: listener.tcp.<name>.send_timeout_close
 ##
 ##
 ## Value: on | off
 ## Value: on | off
 listener.ws.external.send_timeout_close = on
 listener.ws.external.send_timeout_close = on
 
 
-## The TCP receive buffer(os kernel) for external MQTT/Websocket connections.
+## The TCP receive buffer(os kernel) for external MQTT/WebSocket connections.
 ##
 ##
 ## See: listener.tcp.<name>.recbuf
 ## See: listener.tcp.<name>.recbuf
 ##
 ##
 ## Value: Bytes
 ## Value: Bytes
 ## listener.ws.external.recbuf = 4KB
 ## listener.ws.external.recbuf = 4KB
 
 
-## The TCP send buffer(os kernel) for external MQTT/Websocket connections.
+## The TCP send buffer(os kernel) for external MQTT/WebSocket connections.
 ##
 ##
 ## See: listener.tcp.<name>.sndbuf
 ## See: listener.tcp.<name>.sndbuf
 ##
 ##
@@ -1133,17 +1148,22 @@ listener.ws.external.send_timeout_close = on
 ## Value: on | off
 ## Value: on | off
 listener.ws.external.tune_buffer = on
 listener.ws.external.tune_buffer = on
 
 
-## The TCP_NODELAY flag for external MQTT/Websocket connections.
+## The TCP_NODELAY flag for external MQTT/WebSocket connections.
 ##
 ##
 ## See: listener.tcp.<name>.nodelay
 ## See: listener.tcp.<name>.nodelay
 ##
 ##
 ## Value: true | false
 ## Value: true | false
 listener.ws.external.nodelay = true
 listener.ws.external.nodelay = true
 
 
+## The SO_REUSEADDR flag for MQTT/WebSocket Listener.
+##
+## Value: true | false
+listener.ws.external.reuseaddr = true
+
 ##--------------------------------------------------------------------
 ##--------------------------------------------------------------------
 ## External WebSocket/SSL listener for MQTT Protocol
 ## External WebSocket/SSL listener for MQTT Protocol
 
 
-## listener.wss.<name> is the IP address and port that the MQTT/Websocket/SSL
+## listener.wss.<name> is the IP address and port that the MQTT/WebSocket/SSL
 ## listener will bind.
 ## listener will bind.
 ##
 ##
 ## Value: IP:Port | Port
 ## Value: IP:Port | Port
@@ -1151,7 +1171,7 @@ listener.ws.external.nodelay = true
 ## Examples: 8084, 127.0.0.1:8084, ::1:8084
 ## Examples: 8084, 127.0.0.1:8084, ::1:8084
 listener.wss.external = 8084
 listener.wss.external = 8084
 
 
-## The acceptor pool for external MQTT/Websocket/SSL listener.
+## The acceptor pool for external MQTT/WebSocket/SSL listener.
 ##
 ##
 ## Value: Number
 ## Value: Number
 listener.wss.external.acceptors = 4
 listener.wss.external.acceptors = 4
@@ -1161,19 +1181,19 @@ listener.wss.external.acceptors = 4
 ## Value: Number
 ## Value: Number
 listener.wss.external.max_clients = 64
 listener.wss.external.max_clients = 64
 
 
-## TODO: Zone of the external MQTT/Websocket/SSL listener belonged to.
+## TODO: Zone of the external MQTT/WebSocket/SSL listener belonged to.
 ##
 ##
 ## Value: String
 ## Value: String
 ## listener.wss.external.zone = external
 ## listener.wss.external.zone = external
 
 
-## Mountpoint of the MQTT/Websocket/SSL Listener.
+## Mountpoint of the MQTT/WebSocket/SSL Listener.
 ##
 ##
 ## See: listener.tcp.<name>.mountpoint
 ## See: listener.tcp.<name>.mountpoint
 ##
 ##
 ## Value: String
 ## Value: String
 ## listener.wss.external.mountpoint = inbound/
 ## listener.wss.external.mountpoint = inbound/
 
 
-## The access control rules for the MQTT/Websocket/SSL listener.
+## The access control rules for the MQTT/WebSocket/SSL listener.
 ##
 ##
 ## See: listener.tcp.<name>.access.<no>
 ## See: listener.tcp.<name>.access.<no>
 ##
 ##
@@ -1269,35 +1289,35 @@ listener.wss.external.certfile = {{ platform_etc_dir }}/certs/cert.pem
 ## Value: cn | dn
 ## Value: cn | dn
 ## listener.wss.external.peer_cert_as_username = cn
 ## listener.wss.external.peer_cert_as_username = cn
 
 
-## TCP backlog for the Websocket/SSL connection.
+## TCP backlog for the WebSocket/SSL connection.
 ##
 ##
 ## See listener.tcp.<name>.backlog
 ## See listener.tcp.<name>.backlog
 ##
 ##
 ## Value: Number >= 0
 ## Value: Number >= 0
 listener.wss.external.backlog = 1024
 listener.wss.external.backlog = 1024
 
 
-## The TCP send timeout for the Websocket/SSL connection.
+## The TCP send timeout for the WebSocket/SSL connection.
 ##
 ##
 ## See: listener.tcp.<name>.send_timeout
 ## See: listener.tcp.<name>.send_timeout
 ##
 ##
 ## Value: Duration
 ## Value: Duration
 listener.wss.external.send_timeout = 15s
 listener.wss.external.send_timeout = 15s
 
 
-## Close the Websocket/SSL connection if send timeout.
+## Close the WebSocket/SSL connection if send timeout.
 ##
 ##
 ## See: listener.tcp.<name>.send_timeout_close
 ## See: listener.tcp.<name>.send_timeout_close
 ##
 ##
 ## Value: on | off
 ## Value: on | off
 listener.wss.external.send_timeout_close = on
 listener.wss.external.send_timeout_close = on
 
 
-## The TCP receive buffer(os kernel) for the Websocket/SSL connections.
+## The TCP receive buffer(os kernel) for the WebSocket/SSL connections.
 ##
 ##
 ## See: listener.tcp.<name>.recbuf
 ## See: listener.tcp.<name>.recbuf
 ##
 ##
 ## Value: Bytes
 ## Value: Bytes
 ## listener.wss.external.recbuf = 4KB
 ## listener.wss.external.recbuf = 4KB
 
 
-## The TCP send buffer(os kernel) for the Websocket/SSL connections.
+## The TCP send buffer(os kernel) for the WebSocket/SSL connections.
 ##
 ##
 ## See: listener.tcp.<name>.sndbuf
 ## See: listener.tcp.<name>.sndbuf
 ##
 ##
@@ -1311,13 +1331,18 @@ listener.wss.external.send_timeout_close = on
 ## Value: Bytes
 ## Value: Bytes
 ## listener.wss.external.buffer = 4KB
 ## listener.wss.external.buffer = 4KB
 
 
-## The TCP_NODELAY flag for Websocket/SSL connections.
+## The TCP_NODELAY flag for WebSocket/SSL connections.
 ##
 ##
 ## See: listener.tcp.<name>.nodelay
 ## See: listener.tcp.<name>.nodelay
 ##
 ##
 ## Value: true | false
 ## Value: true | false
 ## listener.wss.external.nodelay = true
 ## listener.wss.external.nodelay = true
 
 
+## The SO_REUSEADDR flag for WebSocket/SSL listener.
+##
+## Value: true | false
+listener.wss.external.reuseaddr = true
+
 ##--------------------------------------------------------------------
 ##--------------------------------------------------------------------
 ## HTTP Management API Listener
 ## HTTP Management API Listener
 
 

+ 27 - 1
priv/emq.schema

@@ -850,6 +850,11 @@ end}.
   hidden
   hidden
 ]}.
 ]}.
 
 
+{mapping, "listener.tcp.$name.reuseaddr", "emqttd.listeners", [
+  {datatype, {enum, [true, false]}},
+  hidden
+]}.
+
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 %% SSL Listeners
 %% SSL Listeners
 
 
@@ -932,6 +937,11 @@ end}.
   hidden
   hidden
 ]}.
 ]}.
 
 
+{mapping, "listener.ssl.$name.reuseaddr", "emqttd.listeners", [
+  {datatype, {enum, [true, false]}},
+  hidden
+]}.
+
 {mapping, "listener.ssl.$name.tls_versions", "emqttd.listeners", [
 {mapping, "listener.ssl.$name.tls_versions", "emqttd.listeners", [
   {datatype, string}
   {datatype, string}
 ]}.
 ]}.
@@ -1067,6 +1077,11 @@ end}.
   hidden
   hidden
 ]}.
 ]}.
 
 
+{mapping, "listener.ws.$name.reuseaddr", "emqttd.listeners", [
+  {datatype, {enum, [true, false]}},
+  hidden
+]}.
+
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 %% MQTT/WebSocket/SSL Listeners
 %% MQTT/WebSocket/SSL Listeners
 
 
@@ -1148,6 +1163,11 @@ end}.
   hidden
   hidden
 ]}.
 ]}.
 
 
+{mapping, "listener.wss.$name.reuseaddr", "emqttd.listeners", [
+  {datatype, {enum, [true, false]}},
+  hidden
+]}.
+
 {mapping, "listener.wss.$name.tls_versions", "emqttd.listeners", [
 {mapping, "listener.wss.$name.tls_versions", "emqttd.listeners", [
   {datatype, string}
   {datatype, string}
 ]}.
 ]}.
@@ -1239,7 +1259,8 @@ end}.
                            {recbuf,  cuttlefish:conf_get(Prefix ++ ".recbuf", Conf, undefined)},
                            {recbuf,  cuttlefish:conf_get(Prefix ++ ".recbuf", Conf, undefined)},
                            {sndbuf,  cuttlefish:conf_get(Prefix ++ ".sndbuf", Conf, undefined)},
                            {sndbuf,  cuttlefish:conf_get(Prefix ++ ".sndbuf", Conf, undefined)},
                            {buffer,  cuttlefish:conf_get(Prefix ++ ".buffer", Conf, undefined)},
                            {buffer,  cuttlefish:conf_get(Prefix ++ ".buffer", Conf, undefined)},
-                           {nodelay, cuttlefish:conf_get(Prefix ++ ".nodelay", Conf, true)}])
+                           {nodelay, cuttlefish:conf_get(Prefix ++ ".nodelay", Conf, true)},
+                           {reuseaddr, cuttlefish:conf_get(Prefix ++ ".reuseaddr", Conf, true)}])
               end,
               end,
 
 
     SplitFun = fun(undefined) -> undefined; (S) -> string:tokens(S, ",") end,
     SplitFun = fun(undefined) -> undefined; (S) -> string:tokens(S, ",") end,
@@ -1378,6 +1399,11 @@ end}.
   hidden
   hidden
 ]}.
 ]}.
 
 
+{mapping, "listener.api.$name.reuseaddr", "emqttd.listeners", [
+  {datatype, {enum, [true, false]}},
+  hidden
+]}.
+
 {mapping, "listener.api.$name.handshake_timeout", "emqttd.listeners", [
 {mapping, "listener.api.$name.handshake_timeout", "emqttd.listeners", [
   {datatype, {duration, ms}}
   {datatype, {duration, ms}}
 ]}.
 ]}.