Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netdev #3614

Closed
wants to merge 12 commits into from
Closed

Netdev #3614

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/net/netdev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
scottfeldman marked this conversation as resolved.
Show resolved Hide resolved
)

// netdev is the current netdev, set by the application with useNetdev()
Expand All @@ -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 {

Expand Down
9 changes: 4 additions & 5 deletions src/net/tcpsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"io"
"net/netip"
"strconv"
"syscall"
"time"
)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions src/net/tlssock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"internal/itoa"
"io"
"strconv"
"syscall"
"time"
)

Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions src/net/udpsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"io"
"net/netip"
"strconv"
"syscall"
"time"
)

Expand Down Expand Up @@ -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
}
Expand Down
13 changes: 0 additions & 13 deletions src/syscall/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,3 @@ type Conn interface {
// SyscallConn returns a raw network connection.
SyscallConn() (RawConn, error)
}

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
F_SETFL = 0x4
)
1 change: 1 addition & 0 deletions src/syscall/syscall_libc_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
DT_UNKNOWN = 0x0
DT_WHT = 0xe
F_GETFL = 0x3
F_SETFL = 0x4
O_NONBLOCK = 0x4
)

Expand Down
1 change: 1 addition & 0 deletions src/syscall/syscall_libc_wasi.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const (

// ../../lib/wasi-libc/expected/wasm32-wasi/predefined-macros.txt
F_GETFL = 3
F_SETFL = 4
)

// These values are needed as a stub until Go supports WASI as a full target.
Expand Down