-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
espat: refactor net and tls interface compatible code into separate s…
…ub-packages Signed-off-by: Ron Evans <[email protected]>
- Loading branch information
1 parent
7e78e2c
commit 50633f3
Showing
8 changed files
with
135 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Package tls is intended to provide a minimal set of compatible interfaces with the | ||
// Go standard library's tls package. | ||
package tls | ||
|
||
import ( | ||
"strconv" | ||
|
||
"tinygo.org/x/drivers/espat" | ||
"tinygo.org/x/drivers/espat/net" | ||
) | ||
|
||
// Dial makes a TLS network connection. It tries to provide a mostly compatible interface | ||
// to tls.Dial(). | ||
// Dial connects to the given network address. | ||
func Dial(network, address string, config *Config) (*net.TCPSerialConn, error) { | ||
raddr, err := net.ResolveTCPAddr(network, address) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
addr := raddr.IP.String() | ||
sendport := strconv.Itoa(raddr.Port) | ||
|
||
// disconnect any old socket | ||
espat.ActiveDevice.DisconnectSocket() | ||
|
||
// connect new socket | ||
err = espat.ActiveDevice.ConnectSSLSocket(addr, sendport) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return net.NewTCPSerialConn(net.SerialConn{Adaptor: espat.ActiveDevice}, nil, raddr), nil | ||
} | ||
|
||
// Config is a placeholder for future compatibility with | ||
// tls.Config. | ||
type Config struct { | ||
} |
Oops, something went wrong.