From 2d46776c18276a6b806fe5cc6c58db861e949549 Mon Sep 17 00:00:00 2001 From: Scott Feldman Date: Tue, 2 May 2023 16:39:11 -0700 Subject: [PATCH] move syscall constants for networking into net space to avoid windows build issue --- netdev.go | 12 +++++++++++- tcpsock.go | 9 ++++----- tlssock.go | 3 +-- udpsock.go | 3 +-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/netdev.go b/netdev.go index f7add3b..05150e2 100644 --- a/netdev.go +++ b/netdev.go @@ -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 { diff --git a/tcpsock.go b/tcpsock.go index 6222c97..25a5475 100644 --- a/tcpsock.go +++ b/tcpsock.go @@ -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 } diff --git a/tlssock.go b/tlssock.go index 81c426a..77d0245 100644 --- a/tlssock.go +++ b/tlssock.go @@ -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 } diff --git a/udpsock.go b/udpsock.go index 55bc4c3..9fa2054 100644 --- a/udpsock.go +++ b/udpsock.go @@ -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 }