Decoupled net package from espat

This commit is contained in:
BCG
2019-12-15 11:50:21 -05:00
committed by Ron Evans
parent 7b56e61d52
commit cc5ecafacf
13 changed files with 84 additions and 35 deletions
+38
View File
@@ -0,0 +1,38 @@
// 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/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
net.ActiveDevice.DisconnectSocket()
// connect new socket
err = net.ActiveDevice.ConnectSSLSocket(addr, sendport)
if err != nil {
return nil, err
}
return net.NewTCPSerialConn(net.SerialConn{Adaptor: net.ActiveDevice}, nil, raddr), nil
}
// Config is a placeholder for future compatibility with
// tls.Config.
type Config struct {
}