Allow the socket to be specified
This commit is contained in:
parent
7e0d4fe0cf
commit
1f218f7b48
@ -43,6 +43,7 @@ type link struct {
|
|||||||
|
|
||||||
func newLink(options options.Options) *link {
|
func newLink(options options.Options) *link {
|
||||||
// default values
|
// default values
|
||||||
|
var sock transport.Socket
|
||||||
id := "local"
|
id := "local"
|
||||||
addr := "127.0.0.1:10001"
|
addr := "127.0.0.1:10001"
|
||||||
tr := transport.DefaultTransport
|
tr := transport.DefaultTransport
|
||||||
@ -62,11 +63,19 @@ func newLink(options options.Options) *link {
|
|||||||
tr = ltr.(transport.Transport)
|
tr = ltr.(transport.Transport)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lsock, ok := options.Values().Get("link.socket")
|
||||||
|
if ok {
|
||||||
|
sock = lsock.(transport.Socket)
|
||||||
|
}
|
||||||
|
|
||||||
l := &link{
|
l := &link{
|
||||||
// the remote end to dial
|
// the remote end to dial
|
||||||
addr: addr,
|
addr: addr,
|
||||||
// transport to dial link
|
// transport to dial link
|
||||||
transport: tr,
|
transport: tr,
|
||||||
|
// the socket to use
|
||||||
|
// this is nil if not specified
|
||||||
|
socket: sock,
|
||||||
// unique id assigned to the link
|
// unique id assigned to the link
|
||||||
id: id,
|
id: id,
|
||||||
// the closed channel used to close the conn
|
// the closed channel used to close the conn
|
||||||
|
@ -14,7 +14,8 @@ import (
|
|||||||
type Link interface {
|
type Link interface {
|
||||||
// provides the transport.Socket interface
|
// provides the transport.Socket interface
|
||||||
transport.Socket
|
transport.Socket
|
||||||
// Connect connects the link. It must be called first.
|
// Connect connects the link. It must be called first
|
||||||
|
// if there's an expectation to create a new socket.
|
||||||
Connect() error
|
Connect() error
|
||||||
// Id of the link is "local" if not specified
|
// Id of the link is "local" if not specified
|
||||||
Id() string
|
Id() string
|
||||||
@ -40,12 +41,20 @@ func Id(id string) options.Option {
|
|||||||
return options.WithValue("link.id", id)
|
return options.WithValue("link.id", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The address to use for the link
|
// The address to use for the link. Connect must be
|
||||||
|
// called for this to be used.
|
||||||
func Address(a string) options.Option {
|
func Address(a string) options.Option {
|
||||||
return options.WithValue("link.address", a)
|
return options.WithValue("link.address", a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The transport to use for the link
|
// The transport to use for the link where we
|
||||||
|
// want to dial the connection first.
|
||||||
func Transport(t transport.Transport) options.Option {
|
func Transport(t transport.Transport) options.Option {
|
||||||
return options.WithValue("link.transport", t)
|
return options.WithValue("link.transport", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Socket sets the socket where it was accepted
|
||||||
|
// from a remote end.
|
||||||
|
func Socket(s transport.Socket) options.Option {
|
||||||
|
return options.WithValue("link.socket", s)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user