浏览代码

Merge pull request #1123 from PSUdaemon/add_local_addr

Add LocalAddr to Config struct and honor in broker.Open().
Evan Huus 7 年之前
父节点
当前提交
f7df95cff1
共有 2 个文件被更改,包括 8 次插入0 次删除
  1. 1 0
      broker.go
  2. 7 0
      config.go

+ 1 - 0
broker.go

@@ -86,6 +86,7 @@ func (b *Broker) Open(conf *Config) error {
 		dialer := net.Dialer{
 		dialer := net.Dialer{
 			Timeout:   conf.Net.DialTimeout,
 			Timeout:   conf.Net.DialTimeout,
 			KeepAlive: conf.Net.KeepAlive,
 			KeepAlive: conf.Net.KeepAlive,
+			LocalAddr: conf.Net.LocalAddr,
 		}
 		}
 
 
 		if conf.Net.TLS.Enable {
 		if conf.Net.TLS.Enable {

+ 7 - 0
config.go

@@ -5,6 +5,7 @@ import (
 	"crypto/tls"
 	"crypto/tls"
 	"fmt"
 	"fmt"
 	"io/ioutil"
 	"io/ioutil"
+	"net"
 	"regexp"
 	"regexp"
 	"time"
 	"time"
 
 
@@ -58,6 +59,12 @@ type Config struct {
 		// KeepAlive specifies the keep-alive period for an active network connection.
 		// KeepAlive specifies the keep-alive period for an active network connection.
 		// If zero, keep-alives are disabled. (default is 0: disabled).
 		// If zero, keep-alives are disabled. (default is 0: disabled).
 		KeepAlive time.Duration
 		KeepAlive time.Duration
+
+		// LocalAddr is the local address to use when dialing an
+		// address. The address must be of a compatible type for the
+		// network being dialed.
+		// If nil, a local address is automatically chosen.
+		LocalAddr net.Addr
 	}
 	}
 
 
 	// Metadata is the namespace for metadata management properties used by the
 	// Metadata is the namespace for metadata management properties used by the