Skip to content

Commit 28c56ec

Browse files
committed
net: implement netFD for WASI
Signed-off-by: Roman Volosatovs <[email protected]>
1 parent 169a2d7 commit 28c56ec

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/net/fd_wasi.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//go:build wasi
2+
// +build wasi
3+
4+
package net
5+
6+
import (
7+
"io"
8+
"os"
9+
"syscall"
10+
"time"
11+
)
12+
13+
// Network file descriptor.
14+
type netFD struct {
15+
*os.File
16+
17+
net string
18+
laddr Addr
19+
raddr Addr
20+
}
21+
22+
// Read implements the Conn Read method.
23+
func (c *netFD) Read(b []byte) (int, error) {
24+
// TODO: Handle EAGAIN and perform poll
25+
return c.File.Read(b)
26+
}
27+
28+
// Write implements the Conn Write method.
29+
func (c *netFD) Write(b []byte) (int, error) {
30+
// TODO: Handle EAGAIN and perform poll
31+
return c.File.Write(b)
32+
}
33+
34+
// LocalAddr implements the Conn LocalAddr method.
35+
func (*netFD) LocalAddr() Addr {
36+
return nil
37+
}
38+
39+
// RemoteAddr implements the Conn RemoteAddr method.
40+
func (*netFD) RemoteAddr() Addr {
41+
return nil
42+
}
43+
44+
// SetDeadline implements the Conn SetDeadline method.
45+
func (*netFD) SetDeadline(t time.Time) error {
46+
return ErrNotImplemented
47+
}
48+
49+
// SetReadDeadline implements the Conn SetReadDeadline method.
50+
func (*netFD) SetReadDeadline(t time.Time) error {
51+
return ErrNotImplemented
52+
}
53+
54+
// SetWriteDeadline implements the Conn SetWriteDeadline method.
55+
func (*netFD) SetWriteDeadline(t time.Time) error {
56+
return ErrNotImplemented
57+
}

src/net/net_fake.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
// Fake networking. It is intended to allow tests of other package to pass.
88

9+
//go:build !wasi
10+
// +build !wasi
11+
912
package net
1013

1114
import (

0 commit comments

Comments
 (0)