move syscall constants for networking into net space to avoid windows build issue

This commit is contained in:
Scott Feldman
2023-05-02 16:39:11 -07:00
committed by deadprogram
parent d939a800a7
commit 2d46776c18
4 changed files with 17 additions and 10 deletions
+11 -1
View File
@@ -5,9 +5,19 @@ import (
)
const (
AF_INET = 0x2
SOCK_STREAM = 0x1
SOCK_DGRAM = 0x2
SOL_SOCKET = 0x1
SO_KEEPALIVE = 0x9
SOL_TCP = 0x6
TCP_KEEPINTVL = 0x5
IPPROTO_TCP = 0x6
IPPROTO_UDP = 0x11
// Made up, not a real IP protocol number. This is used to create a
// TLS socket on the device, assuming the device supports mbed TLS.
IPPROTO_TLS = 0xFE
F_SETFL = 0x4
)
// netdev is the current netdev, set by the application with useNetdev()
@@ -31,7 +41,7 @@ func useNetdev(dev netdever) {
//
// NOTE: The netdever interface is mirrored in drivers/netdev.go.
// NOTE: If making changes to this interface, mirror the changes in
// NOTE: drivers/netdev.go, and visa-versa.
// NOTE: drivers/netdev.go, and vice-versa.
type netdever interface {
+4 -5
View File
@@ -12,7 +12,6 @@ import (
"io"
"net/netip"
"strconv"
"syscall"
"time"
)
@@ -154,7 +153,7 @@ func DialTCP(network string, laddr, raddr *TCPAddr) (*TCPConn, error) {
return nil, fmt.Errorf("Sorry, localhost isn't available on Tinygo")
}
fd, err := netdev.Socket(syscall.AF_INET, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
fd, err := netdev.Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
if err != nil {
return nil, err
}
@@ -217,12 +216,12 @@ func (c *TCPConn) SetDeadline(t time.Time) error {
}
func (c *TCPConn) SetKeepAlive(keepalive bool) error {
return netdev.SetSockOpt(c.fd, syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, keepalive)
return netdev.SetSockOpt(c.fd, SOL_SOCKET, SO_KEEPALIVE, keepalive)
}
func (c *TCPConn) SetKeepAlivePeriod(d time.Duration) error {
// Units are 1/2 seconds
return netdev.SetSockOpt(c.fd, syscall.SOL_TCP, syscall.TCP_KEEPINTVL, 2*d.Seconds())
return netdev.SetSockOpt(c.fd, SOL_TCP, TCP_KEEPINTVL, 2*d.Seconds())
}
func (c *TCPConn) SetReadDeadline(t time.Time) error {
@@ -266,7 +265,7 @@ func (l *listener) Addr() Addr {
}
func listenTCP(laddr *TCPAddr) (Listener, error) {
fd, err := netdev.Socket(syscall.AF_INET, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
fd, err := netdev.Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
if err != nil {
return nil, err
}
+1 -2
View File
@@ -12,7 +12,6 @@ import (
"internal/itoa"
"io"
"strconv"
"syscall"
"time"
)
@@ -58,7 +57,7 @@ func DialTLS(addr string) (*TLSConn, error) {
port = 443
}
fd, err := netdev.Socket(syscall.AF_INET, syscall.SOCK_STREAM, IPPROTO_TLS)
fd, err := netdev.Socket(AF_INET, SOCK_STREAM, IPPROTO_TLS)
if err != nil {
return nil, err
}
+1 -2
View File
@@ -12,7 +12,6 @@ import (
"io"
"net/netip"
"strconv"
"syscall"
"time"
)
@@ -169,7 +168,7 @@ func DialUDP(network string, laddr, raddr *UDPAddr) (*UDPConn, error) {
laddr.Port = ephemeralPort()
}
fd, err := netdev.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP)
fd, err := netdev.Socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
if err != nil {
return nil, err
}